C# 在长树中使用Newtonsoft.Json
我试图从JSON响应中获取一些信息,但失败了;我想这可能与我使用新图书馆的方式有关 下面是我试图从中获取数据的JSON实例C# 在长树中使用Newtonsoft.Json,c#,json,json.net,console-application,json-deserialization,C#,Json,Json.net,Console Application,Json Deserialization,我试图从JSON响应中获取一些信息,但失败了;我想这可能与我使用新图书馆的方式有关 下面是我试图从中获取数据的JSON实例 { "profileChanges":[ { "changeType":"fullProfileUpdate", "profile":{ "stats":{ "attributes":{ "allowed_to_receive_gi
{
"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#
但它根本不起作用
我调试了它并发现了此异常:
'Newtonsoft.Json.Linq.JArray' does not contain a definition for 'profile'
我做错了什么以及如何修复它?如您问题下的评论所述,
profileChanges
是一个数组,因此您需要指定要访问数组中的哪个项
您确定以下选项不起作用吗?它对我有用
string platform = json.profileChanges[0].profile.stats.attributes.current_mtx_platform;
1.您没有显示完整的json数据(当前的模式无效)。2.
profileChanges
是一个集合,因此它可能是:json.profileChanges[0]。profile
。3.但它根本不起作用-这不是我们可以帮助解决的具体问题,请提供更多信息,您是否收到错误/异常?异常消息或可能的堆栈跟踪是什么?profileChanges
是一个数组,因此您必须以数组的形式访问它,因此不能执行json.profileChanges.profile
,json.profileChanges
不包含名为profile
的属性,因为它是一个数组,因此。…JArray'不包含“profile”的定义。
string platform = json.profileChanges[0].profile.stats.attributes.current_mtx_platform;