格式如下:
[
{"id":0,"email":"abc0@gmail.com","age":0},
{"id":1,"email":"abc1@gmail.com","age":2},
{"id":2,"email":"abc2@gmail.com","age":4},
{"id":3,"email":"abc3@gmail.com","age":6},
{"id":4,"email":"abc4@gmail.com","age":8}]
我想在想解析这个字符串 就是想得到 id email age 的值。
PS:wince程序 vs2005 创建的
9 个解决方案
#1
这样
调用方法
List<Person> appResult = JSONToObject<List<Person>>(@"[{""id"":0,""email"":""abc0@gmail.com"",""age"":0},{""id"":1,""email"":""abc1@gmail.com"",""age"":2},{""id"":2,""email"":""abc2@gmail.com"",""age"":4},{""id"":3,""email"":""abc3@gmail.com"",""age"":6},{""id"":4,""email"":""abc4@gmail.com"",""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);
}
}
调用方法
List<Person> appResult = JSONToObject<List<Person>>(@"[{""id"":0,""email"":""abc0@gmail.com"",""age"":0},{""id"":1,""email"":""abc1@gmail.com"",""age"":2},{""id"":2,""email"":""abc2@gmail.com"",""age"":4},{""id"":3,""email"":""abc3@gmail.com"",""age"":6},{""id"":4,""email"":""abc4@gmail.com"",""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);
}
}
#2
你需要升级到VS2008 。net 3.5 sp1
或者采用第三方组件,如
JSON.NET
下载
http://json.codeplex.com/
或者采用第三方组件,如
JSON.NET
下载
http://json.codeplex.com/
#3
get传递数据量也不大,自己写方法解析吧
#4
求教 就是不会解析啊 您说的解析是 自己拆分字符串?
#5
http://blog.csdn.net/justsoloving/article/details/5794563
简单的jsonhelper
简单的jsonhelper
#6
升级到 vs2008 ,net c f3.5 还是 没有System.Runtime.Serialization.StreamingContext 这个
真郁闷 我看 json.net 里面必须得有这个 貌似
真郁闷 我看 json.net 里面必须得有这个 貌似
#7
javascriptserial类估计也行吧。
#8
Newtonsoft.Json.Net20
#9
楼主,这个问题解决了吗?能否能个代码看看?
#1
这样
调用方法
List<Person> appResult = JSONToObject<List<Person>>(@"[{""id"":0,""email"":""abc0@gmail.com"",""age"":0},{""id"":1,""email"":""abc1@gmail.com"",""age"":2},{""id"":2,""email"":""abc2@gmail.com"",""age"":4},{""id"":3,""email"":""abc3@gmail.com"",""age"":6},{""id"":4,""email"":""abc4@gmail.com"",""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);
}
}
调用方法
List<Person> appResult = JSONToObject<List<Person>>(@"[{""id"":0,""email"":""abc0@gmail.com"",""age"":0},{""id"":1,""email"":""abc1@gmail.com"",""age"":2},{""id"":2,""email"":""abc2@gmail.com"",""age"":4},{""id"":3,""email"":""abc3@gmail.com"",""age"":6},{""id"":4,""email"":""abc4@gmail.com"",""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);
}
}
#2
你需要升级到VS2008 。net 3.5 sp1
或者采用第三方组件,如
JSON.NET
下载
http://json.codeplex.com/
或者采用第三方组件,如
JSON.NET
下载
http://json.codeplex.com/
#3
get传递数据量也不大,自己写方法解析吧
#4
求教 就是不会解析啊 您说的解析是 自己拆分字符串?
#5
http://blog.csdn.net/justsoloving/article/details/5794563
简单的jsonhelper
简单的jsonhelper
#6
升级到 vs2008 ,net c f3.5 还是 没有System.Runtime.Serialization.StreamingContext 这个
真郁闷 我看 json.net 里面必须得有这个 貌似
真郁闷 我看 json.net 里面必须得有这个 貌似
#7
javascriptserial类估计也行吧。
#8
Newtonsoft.Json.Net20
#9
楼主,这个问题解决了吗?能否能个代码看看?