首页 新闻 会员 周边 捐助

json取值

0
悬赏园豆:10 [已解决问题] 解决于 2015-08-28 14:19

这个是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;
} 我这样转的,为什么转不出来

..00..的主页 ..00.. | 初学一级 | 园豆:49
提问于:2015-08-25 14:49
< >
分享
最佳答案
0

用JavaScriptSerializer的Deserialize<T>(string)方法

收获园豆:10
Dayiba狼 | 初学一级 |园豆:33 | 2015-08-25 15:30
 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.. | 园豆:49 (初学一级) | 2015-08-26 14:26

@..00..: 参考http://q.cnblogs.com/q/42653/ 

Dayiba狼 | 园豆:33 (初学一级) | 2015-08-27 11:45

@..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狼 | 园豆:33 (初学一级) | 2015-08-27 11:59

@Dayiba狼: 谢谢,我知道了,一个是转实体类,一个是转List<实体类>、

..00.. | 园豆:49 (初学一级) | 2015-08-28 14:19
其他回答(2)
0

循环取呗,还能怎么快捷?js都是直接写属性,你还想怎么快捷?

顾晓北 | 园豆:10898 (专家六级) | 2015-08-25 15:05
0

属性加 [DataMember]

powerixao | 园豆:401 (菜鸟二级) | 2015-08-27 11:58
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册