用C#json.net解析json

时间:2013-04-22 22:17:35

标签: .net json.net

我有以下json:

[
{
  "Action":"Create",
  "Date":"Sat, 13 Aug 2011 00:38:17 GMT",
  "EventTypeName":"CommentEvent",
  "FriendlyDate":"4 days ago",
  "Idea":{
    "Id":4479,
    "AvgRatingRounded":0,
    "BusinessUnitName":"Consumer: Personal Finance",
    "PunchLine":"API Test idea",
    "ScoreRecent":4.31,
    "StatusName":"Just an idea, not working on it",
    "SubmittedOn":"\/Date(1313195896000-0700)\/",
    "SubmitterName":"Bryant Chou"
  },
  "Subject":"Idea",
  "Summary":"Bryant Chou commented on idea API Test idea",
  "User":{
    "Id":11362,
    "DisplayName":"Bryant",
    "EmailWork":"Bryant@blah.com",
    "Location":"",
    "Phone":"650-555-5555",
    "PhotoExists":true,
    ,
    "PhotoUrl_36x36":
      "http:\/\/localhost.localhost\/Files\/Tenant_1\/DirPhotos\/Small\/11362_3.jpg"
  }
},
{
  "Action":"Create",
  "Date":"Fri, 12 Aug 2011 17:25:57 GMT",
  "EventTypeName":"CommentEvent",
  "FriendlyDate":"4 days ago",
  "Idea":{
    "Id":4477,
    "AvgRatingRounded":0,
    "BusinessUnitName":"Consumer: Personal Finance",
    "PunchLine":"API Test idea",
    "ScoreRecent":4.31,
    "StatusName":"Just an idea, not working on it",
    "SubmittedOn":"\/Date(1313169956000-0700)\/",
    "SubmitterName":"Bryant Chou"
  },
  "Subject":"Idea",
  "Summary":"Bryant Chou commented on idea API Test idea",
  "User":{
    "Id":11362,
    "DisplayName":"Bryant",
    "EmailWork":"Bryant@blah.com",
    "Location":"",
    "Phone":"650-555-5555",
    "PhotoExists":true,
    "PhotoUrl_36x36":
        "http:\/\/localhost.localhost\/Files\/Tenant_1\/DirPhotos\/Small\/11362_3.jpg"
    }
  }
]

我可以使用

JArray a = JArray.Parse(GetJSONPeople());



        GridView1.DataSource = a;
        GridView1.DataBind();

并绑定到网格,但它没有我需要的所有信息。

行动 日期 EventTypeName FriendlyDate 学科 总结

但是我需要在Idea部分中使用ID,我需要在StringBuilder中编写它。我希望这有道理吗?

1 个答案:

答案 0 :(得分:0)

我没有正确获取数据。

我需要使用以下内容:

var jsonObject = JsonConvert.DeserializeObject<List<Class1>>(GetJSONPeople());