开发者

Convert a json with nested json into an object in c#?

I've seen a fair number of questions along these lines and have tried a number of the suggested solutions,开发者_开发问答 but just can't seem to crack this. I'm trying to convert a JSON into an object within c#. The JSON in question has an unusual (for me) layout and contains a nested JSON and a separate array. Any advice would be much appreciated. I've pasted in two records of the JSON below. My efforts have consisted of creating a class that matches the JSON layout and attempting to deserialize into this class. I can provide the code as helpful.

JSON:

[ [ { "eid" : "113580662029802",
      "eids" : [ 113580662029802 ],
      "event_date" : "Thursday, April 28th, 2011",
      "event_id" : "2476353",
      "event_notes" : "",
      "event_time" : "8:00 pm",
      "event_time_8601" : "2011-04-28T20:00:00-04:00",
      "event_timestamp" : 1304035200,
      "event_title" : "Colin Hay",
      "facebook_event_url" : "http://www.facebook.com/event.php?eid=113580662029802",
      "lat" : "42.2793",
      "links" : [ { "link_title" : "8:00 pm",
            "link_type" : "ticket",
            "link_url" : "http://tickets.sonicliving.com/event/2476353/sl-tickets"
          } ],
      "lon" : "-83.7486",
      "poster_url_large" : "http://posters.sonicliving.com/event/2476353/poster.png",
      "poster_url_small" : "http://posters.sonicliving.com/event/2476353/smallposter.png",
      "rsvp" : "1",
      "venue_address" : "316 S. Main St.",
      "venue_city" : "Ann Arbor",
      "venue_country" : "US",
      "venue_id" : "3919",
      "venue_name" : "The Ark",
      "venue_phone" : "(800) 745-3000",
      "venue_state" : "MI"
    } ],
  [ { "eid" : "199014973442276",
      "eids" : [ 199014973442276 ],
      "event_date" : "Wednesday, April 13th, 2011",
      "event_id" : "2801497",
      "event_notes" : "",
      "event_time" : "8:00 pm",
      "event_time_8601" : "2011-04-13T20:00:00-04:00",
      "event_timestamp" : 1302739200,
      "event_title" : "Tobacco / Beans / SHAPERS",
      "facebook_event_url" : "http://www.facebook.com/event.php?eid=199014973442276",
      "lat" : "42.2804",
      "links" : [ { "link_title" : "8:00 pm",
            "link_type" : "details",
            "link_url" : "http://sonicliving.com/event/2801497"
          } ],
      "lon" : "-83.7512",
      "poster_url_large" : "http://posters.sonicliving.com/event/2801497/poster.png",
      "poster_url_small" : "http://posters.sonicliving.com/event/2801497/smallposter.png",
      "rsvp" : "6",
      "venue_address" : "208 S 1st St",
      "venue_city" : "Ann Arbor",
      "venue_country" : "US",
      "venue_id" : "29340",
      "venue_name" : "Blind Pig",
      "venue_phone" : "(734) 996-8555",
      "venue_state" : "MI"
    } ]
]


I recommend creating the object structure in C# (classes, etc) then using JavaScriptSerializer (and possibly creating your own JavaScriptConverter) to parse the information in to those objects.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜