如何使用字符串中的HTTP状态代码返回JSON响应。
使用什么格式?
我尝试了以下代码
protected override string ConvertResponseToString(HttpWebResponse httpResponse)
{
using (StreamReader streamReader = new StreamReader(httpResponse.GetResponseStream(), Encoding.UTF8))
{
HttpStatusCode statusCode = ((HttpWebResponse)httpResponse).StatusCode;
**return statusCode + streamReader.ReadToEnd();**
}
}
答案 0 :(得分:0)
在项目中引用.NET框架程序集System.Web.Helpers.dll。
然后使用JSON类将数据对象转换为JavaScript Object Notation(JSON)格式的字符串:
return Json.Encode(statusCode + streamReader.ReadToEnd());