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這是一個巨大的疏忽。你是否願意將此作爲答案,以便我可以相應接受?你的建議已經解決了這個問題 –