在 WP8 中解析不同的 Json 个对象

Parsing Different Json Objects in WP8

请帮助我解析这个 Json 示例,因为它的复杂性以及其中的不同对象,我无法解析它。我能够解析 Json 当相同对象和相同结构的列表但不像下面的列表时。

   [
      {

       "notificationBrowserHead":
       {

           "notificationId": 4,
           "notificationType": "NEW_PRODUCT",
           "creationTime": 1421933381000,
           "notificationNormalUserId": 4,
           "notificationViewed": false
       },
       "brandIdAndNameHolder":
       {
           "brandId": 1,
           "name": "B1"
       },
       "brandLogo": null,
       "productIdAndNameHolder":
       {
           "productId": 1,
           "name": "JK product1"
       }
   },
   {
       "notificationBrowserHead":
       {
           "notificationId": 2,
           "notificationType": "USER_INT_COMMENT",
           "creationTime": 1421924403000,
           "notificationNormalUserId": 2,
           "notificationViewed": false
       },
       "uploadId": 22,
       "uploadThumbnail": "/mediaUrl/location/thumbNail",
       "uploadDescription": "upload 1 location desc",
       "notificationCreator":
       {
           "normalUserId": 90,
           "displayName": "amit"
       },
       "uploadRemoved": false
   },
   {
       "notificationBrowserHead":
       {
           "notificationId": 1,
           "notificationType": "NEW_LOCATION_VOTE",
           "creationTime": 1421924403000,
           "notificationNormalUserId": 1,
           "notificationViewed": false
       },
       "locationIdAndNameHolder":
       {
           "locationId": 11,
           "name": "Current King JK"
       },
       "locationLogo": null
   }
]     

任何帮助将不胜感激。

制作 class "Notifications (or something)" 并将您从 json2csharp.com 站点返回的所有内容放入其中,然后使用此框架 http://www.newtonsoft.com/json 在您从服务器下载数据时反序列化数据并您应该能够通过 Object.Notificationbrowserhead[x].notificationType 或类似方式获得 notificationType。

我假设当您的 NotificationType 不同时,您会收到一组不同的 json 属性。

解决方案 1:

在 Class 中定义您的所有成员(您为不同类型的通知收到的所有属性的集合)并将其用于反序列化,以便您的特定通知类型不需要的属性将空。

解决方案 2:

手动解析。 Newtonsoft json documentation here