-3

在字符串变量中捕获 Http 响应。我想将字符串转换为 json。如何转换?

  string responseData;  
  HttpWebResponse response = request.GetResponse() as HttpWebResponse;  
   if (response.StatusCode == HttpStatusCode.OK)  
   {
         System.IO.StreamReader responseReader = new System.IO.StreamReader(request.GetResponse().GetResponseStream());
         responseData = responseReader.ReadToEnd();
   }
4

1 回答 1

0

首先看这个之前的讨论

如果您使用 asp.net MVC ,请尝试以下方式

 [HttpGet]
        public JsonResult GetValues()
        {
         string responseData;  
         HttpWebResponse response = request.GetResponse() as HttpWebResponse;  
         if (response.StatusCode == HttpStatusCode.OK)  
         {
         System.IO.StreamReader responseReader = new System.IO.StreamReader(request.GetResponse().GetResponseStream());
         responseData = responseReader.ReadToEnd();
         }                 
         return Json(new { data = responseData}, JsonRequestBehavior.AllowGet);
         }
于 2013-10-17T11:19:05.420 回答