gpt4 book ai didi

c# - Newtonsoft.Json 在长树中的用法

转载 作者:太空宇宙 更新时间:2023-11-03 14:46:23 25 4
gpt4 key购买 nike

我正在尝试从 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;

关于c# - Newtonsoft.Json 在长树中的用法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53987538/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com