Newtonsoft.Json 长树中的用法

Newtonsoft.Json Usage in long trees

我正在尝试从 JSON 响应中抓取一些信息,但它失败了;我认为这可能与我使用新图书馆的方式有关。

下面是我试图从中获取数据的 JSON 实例;

{
   "profileChanges":[
      {
         "changeType":"fullProfileUpdate",
         "profile":{
            "stats":{
               "attributes":{
                  "allowed_to_receive_gifts":true,
                  "allowed_to_send_gifts":true,
                  "ban_history":{},
                  //This is what I'm trying to scrape the EpicPCKorea string
                  "current_mtx_platform":"EpicPCKorea",
                  "daily_purchases":{},
                  "gift_history":{},
                  "import_friends_claimed":{},
                  "in_app_purchases":{
                     "fulfillmentCounts":{
                        "2E5AC9924F2247325BBB22AC9AF9965B":1
                     },
                     "receipts":[
                        "EPIC:543a35e70dde4e0aaf56a9e0b76c8f67"
                     ]
                  },
                  "inventory_limit_bonus":0,
                  "mfa_enabled":false,
                  "monthly_purchases":{},
                  "mtx_affiliate":"",
                  "mtx_purchase_history":{},
                  "weekly_purchases":{}
               }
            },
            "updated":"2018-12-06T14:37:27.797Z",
         }
      }
   ],
   "profileChangesBaseRevision":31,
   "serverTime":"2018-12-30T18:44:35.451Z"
}

在这里,我的 C# 代码;

//str4 is the json response that I just posted up.
dynamic json    = JsonConvert.DeserializeObject(str4); 
string platform = json.profileChanges.profile.stats.attributes.current_mtx_platform;

但是根本不起作用

我调试了一下,发现了这个异常:

'Newtonsoft.Json.Linq.JArray' does not contain a definition for 'profile'

我做错了什么,我该如何解决?

如您问题下的评论所述,profileChanges 是一个数组,因此您需要指定要访问数组中的哪个项目。

你确定下面的方法不起作用吗?它对我有用...

string platform = json.profileChanges[0].profile.stats.attributes.current_mtx_platform;