0
我有REST的Web服務,讓我的JSON數據,我消費從Android的JSON數據,現在我想從ASP消費它,我嘗試這樣做:ASP使用JSON數據空結果
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
}
}
}
}
我空的頁面,爲什麼請?如何解決它?也許我得到的結果,但我不打印?在此先感謝
你明白了什麼,當你在瀏覽器中導航到「http:// localhost:8080/test2/eattel/cities」? – I4V
我得到14個城市,每個人的名稱和ID – user2387331
@ I4V我可以從我的Android項目中消費JSON – user2387331