json.net我如何解析对象

时间:2014-04-30 05:53:06

标签: c# json json.net

我在得到结果之前测试了json 但是试图用这个来弄清楚但是它没有工作

我不需要其他解决方案来获取表[0] .id 我想知道如何将所有数据添加到对象

       {"table:[{"name":"ali","id":"1","id_f":"1","x":"11","y":"10","r":"0","w":"100","h":"100"}]}




 public class Table
    {
        public string name { get; set; }
        public string id { get; set; }
        public string id_f { get; set; }
        public string x { get; set; }
        public string y { get; set; }
        public string o { get; set; }
        public string w { get; set; }
        public string h { get; set; }
    }

    public class RootObject
    {
        public List<Table> table { get; set; }
    }

       RootObject aa = new RootObject();
        aa=JToken.Parse(result).ToObject<RootObject>();//result is the json data
        ttt.Text = aa.table[0].id; 

1 个答案:

答案 0 :(得分:0)

使用JsonConvert.DeserializeObject

var rootObject = JsonConvert.DeserializeObject<RootObject>(result)