C# 后台 通过http get得到一个 json字符串
格式如下:
[
{"id":0,"email":"[email protected]","age":0},
{"id":1,"email":"[email protected]","age":2},
{"id":2,"email":"[email protected]","age":4},
{"id":3,"email":"[email protected]","age":6},
{"id":4,"email":"[email protected]","age":8}]
我想在想解析这个字符串 就是想得到 id email age 的值。
PS:wince程序 vs2005 创建的
格式如下:
[
{"id":0,"email":"[email protected]","age":0},
{"id":1,"email":"[email protected]","age":2},
{"id":2,"email":"[email protected]","age":4},
{"id":3,"email":"[email protected]","age":6},
{"id":4,"email":"[email protected]","age":8}]
我想在想解析这个字符串 就是想得到 id email age 的值。
PS:wince程序 vs2005 创建的
List<Person> appResult = JSONToObject<List<Person>>(@"[{""id"":0,""email"":""[email protected]"",""age"":0},{""id"":1,""email"":""[email protected]"",""age"":2},{""id"":2,""email"":""[email protected]"",""age"":4},{""id"":3,""email"":""[email protected]"",""age"":6},{""id"":4,""email"":""[email protected]"",""age"":8}]");
for(int i = 0;i<appResult.Count;i++)
输出(appResult[i].id);//定义
public class Person
{
public int id { set; get; }
public String email { set; get; }
public int age { set; get; }
}
public static T JSONToObject<T>(string jsonText)
{
System.Web.Script.Serialization.JavaScriptSerializer jss = new System.Web.Script.Serialization.JavaScriptSerializer();
try
{
return jss.Deserialize<T>(jsonText);
}
catch (Exception ex)
{
throw new Exception("JSONHelper.JSONToObject(): " + ex.Message);
}
}
JSON.NET下载
http://json.codeplex.com/
简单的jsonhelper