这个是string类型里面的值,我只想取到“data”里面的键值,怎么取快捷方便?{
"action" : "get",
"uri" : "http://a1.easemob.com/",
"entities" : [ ],
"data" : [ {
"owner" : "1"
}, {
"member" : "2"
} ],
"timestamp" : 1440481430264,
"duration" : 3
}
public class GroupsMember { /// <summary> /// /// </summary> public string action { get; set; } /// <summary> /// /// </summary> public string uri { get; set; } /// <summary> /// /// </summary> public int timestamp { get; set; } /// <summary> /// /// </summary> public int duration { get; set; } /// <summary> /// /// </summary> public object entities { get; set; } /// <summary> /// 群成员 /// </summary> public object data { get; set; } }
List<GroupsMember> products = new List<GroupsMember>();
products = ToJsonTran.JSONStringToList<GroupsMember>(字符串);
public static List<T> JSONStringToList<T>(string JsonStr)
{
JavaScriptSerializer Serializer = new JavaScriptSerializer();
List<T> objs = Serializer.Deserialize<List<T>>(JsonStr);
return objs;
} 我这样转的,为什么转不出来
用JavaScriptSerializer的Deserialize<T>(string)方法
public class GroupsMember { /// <summary> /// /// </summary> public string action { get; set; } /// <summary> /// /// </summary> public string uri { get; set; } /// <summary> /// /// </summary> public int timestamp { get; set; } /// <summary> /// /// </summary> public int duration { get; set; } /// <summary> /// /// </summary> public object entities { get; set; } /// <summary> /// 群成员 /// </summary> public object data { get; set; } }
List<GroupsMember> products = new List<GroupsMember>();
products = ToJsonTran.JSONStringToList<GroupsMember>(字符串);
public static List<T> JSONStringToList<T>(string JsonStr)
{
JavaScriptSerializer Serializer = new JavaScriptSerializer();
List<T> objs = Serializer.Deserialize<List<T>>(JsonStr);
return objs;
} 我这样写的,但是转不出来,为什么
@..00..: 参考http://q.cnblogs.com/q/42653/
@..00..:
public class GroupsMember { /// <summary> /// /// </summary> public string action { get; set; } /// <summary> /// /// </summary> public string uri { get; set; } /// <summary> /// /// </summary> public int timestamp { get; set; } /// <summary> /// /// </summary> public int duration { get; set; } /// <summary> /// /// </summary> public List<Dictionary<string, string>> entities { get; set; } /// <summary> /// 群成员 /// </summary> public List<Dictionary<string, string>> data { get; set; } }
@Dayiba狼: 谢谢,我知道了,一个是转实体类,一个是转List<实体类>、
循环取呗,还能怎么快捷?js都是直接写属性,你还想怎么快捷?
属性加 [DataMember]