现在的位置: 首页 > 综合 > 正文

.net中反序列化json对象方法(使用Dynamic)

2013年02月09日 ⁄ 综合 ⁄ 共 453字 ⁄ 字号 评论关闭
using Newtonsoft.Json;//命名空间的引入:添加Newtonsoft.Json.dll(可以在网上下载)

#region .net中反序列化json对象方法(使用Dynamic)
        string json = "[{\"value\":\"test1\",\"score\":90},{\"value\":\"test2\",\"score\":70},{\"value\":\"test3\",\"score\":100}]";
        dynamic newValue = JsonConvert.DeserializeObject<dynamic>(json);
        for (int i = 0; i < newValue.Count; i++)
        {
            string value = newValue[i]["value"].Value;
            //int score = Convert.ToInt32(newValue[i]["score"].Value);
            long score = newValue[i]["score"].Value;
        }

 #endregion

抱歉!评论已关闭.