我有REST Web服务,给我json数据,我从android消耗了json数据,现在我想从ASP中使用它,我试过这个:
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
// corrected to WebRequest from HttpWebRequest
WebRequest request = WebRequest.Create("http://localhost:8080/test2/eattel/cities");
request.Method = "GET";
request.ContentType = "application/json; charset=utf-8";
//get response-stream, and use a streamReader to read the content
using (Stream s = request.GetResponse().GetResponseStream())
{
using (StreamReader sr = new StreamReader(s))
{
var jsonData = sr.ReadToEnd();
//decode jsonData with javascript serializer
}
}
}
}
我有空页,为什么好吗?怎么解决?也许我得到的结果,但我不打印它?提前谢谢
答案 0 :(得分:1)
这不是真正的答案,但我建议任何使用.NET中的JSON的人 - ServiceStack(http://www.servicestack.net/mythz_blog/?p=344)
检查其他StackOverflow:How can I deserialize JSON in C#?