private void button5_Click(object sender, EventArgs e)
{
//string dd=System.Guid.NewGuid().ToString("N");
//[{"aqi":60,"area":"\u5317\u4eac","pm2_5":3,"pm2_5_24h":43,"position_name":"\u4e07\u5bff\u897f\u5bab","primary_pollutant":"\u9897\u7c92\u7269(PM2.5)","quality":"\u826f","station_code":"1001A","time_point":"2013-05-29T09:00:00Z"}] var json = HandlerResponse("http://www.pm25.in/api/querys/pm2_5.json?city=北京&token=5j1znBVAsnSf5xQyNQyq", "GET");
//var jsonReader = new JsonTextReader(new StringReader(json)); //var jArray = (JArray)new JsonSerializer().Deserialize(jsonReader);
////var jObject = (JObject)new JsonSerializer().Deserialize(jsonReader);对应//{"aqi":60,"area":"\u5317\u4eac","pm2_5":3,"pm2_5_24h":43,"position_name":"\u4e07\u5bff\u897f\u5bab","primary_pollutant":"\u9897\u7c92\u7269(PM2.5)","quality":"\u826f","station_code":"1001A","time_point":"2013-05-29T09:00:00Z"} //foreach (var dr in jArray) //{ // var jObject = jArray[0]; // var aqi = (int)dr["aqi"]; // var area = (string)dr["area"]; // var pm2_5 = (int)dr["pm2_5"]; // var pm2_5_24h = (int)dr["pm2_5_24h"]; //}
//方法二 //var jArray = JsonConvert.DeserializeObject<JArray>(json); //foreach (JObject obj in jArray.Values<JObject>()) //{ // var aqi = (int)obj["aqi"]; //}
//方法三 var jArray = JArray.Parse(json); foreach (JObject obj in jArray) { var aqi = obj["aqi"].Value<int>(); } }
//public static JObject ReadJson(this RequestContext context) //{ // using (var streamReader = new StreamReader(context.InputStream, context.GetEncoding())) // using (var jsonReader = new JsonTextReader(streamReader)) // return JObject.Load(jsonReader); //}
//public static T ReadJson<T>(this RequestContext context) //{ // using (var streamReader = new StreamReader(context.InputStream, context.GetEncoding())) // using (var jsonReader = new JsonTextReader(streamReader)) // return (T)new JsonSerializer().Deserialize(jsonReader, typeof(T)); //}
//public static object ReadJsonObject(this RequestContext context) //{ // using (var streamReader = new StreamReader(context.InputStream, context.GetEncoding())) // using (var jsonReader = new JsonTextReader(streamReader)) // return new JsonSerializer().Deserialize(jsonReader); //}
//public static JArray ReadJsonArray(this RequestContext context) //{ // using (var streamReader = new StreamReader(context.InputStream, context.GetEncoding())) // using (var jsonReader = new JsonTextReader(streamReader)) // return JArray.Load(jsonReader); //}
//public static string ReadString(this RequestContext context) //{ // using (var streamReader = new StreamReader(context.InputStream, context.GetEncoding())) // return streamReader.ReadToEnd(); //}