1
我与Json.net工作没有找到属性值,我从一个网页检索以下JSON:JSON.net当属性存在
"{\"Response\":
[{
\"iconPath\":\"",
\"membershipType\":1,
\"membershipId\":\"124877458474\",
\"displayName\":\"DarylJG\"
}],
\"ErrorCode\":1,
\"ThrottleSeconds\":0,
\"ErrorStatus\":\"Success\",
\"Message\":\"Ok\",
\"MessageData\":{ }}"
现在,我收到以下错误,当试图从这个属性返回一个字符串:
型 “Microsoft.CSharp.RuntimeBinder.RuntimeBinderException”未处理的异常发生在 System.Core.dll
附加信息:“Newtonsoft.Json.Linq.JArray”不包含 为“iconPath”
哪个iconPath这是否JSON文件中存在的定义。我使用的代码:
var response = client.GetAsync("CorrectServerPath & Auth").Result;
var content = response.Content.ReadAsStringAsync().Result;
dynamic item = Newtonsoft.Json.JsonConvert.DeserializeObject(content);
return item.Response.iconPath;
这是代码这是引发此错误的线路,但下面的代码:
return item.Message;
将返回OK
所以我的整体问题是,如何使用JSON.net在提供的json文件中达到iconPath?因为,我不知所措。研究材料什么也没有&可能使用不正确的搜索条件
你'Response'构件是一个数组,而不是一个对象。尝试'item.Response [0] .iconPath' –
@CollinDauphinee这是一个巨大的疏忽。你是否愿意将此作为答案,以便我可以相应接受?你的建议已经解决了这个问题 –