0

我有 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
            }
        }
    }
}

我有空白页,请问为什么?如何解决?也许我得到了结果,但我没有打印它?提前致谢

4

1 回答 1

1

这不是真正的答案,但我建议任何在 .NET 中使用 JSON 的人 - ServiceStack ( http://www.servicestack.net/mythz_blog/?p=344 )

检查另一个 StackOverflow:如何在 C# 中反序列化 JSON?

于 2013-05-27T22:27:41.177 回答