我想在C#.NET 解析JSON字符串,但它拋出異常JSON字符串解析
string str= "{\"id\"=>\"\", \"textContent\"=>\"Services\", \"nodeName\"=>\"SPAN\", \"class\"=>\"ng-binding\", \"html\"=>\"<span class=\"ng-binding\">Services</span>\", \"rect\"=>{\"center_y\"=>252, \"center_x\"=>90, \"height\"=>26, \"width\"=>180, \"bottom\"=>108, \"left\"=>0, \"right\"=>90, \"y\"=>240, \"x\"=>0, \"top\"=>95}, \"nodeType\"=>\"ELEMENT_NODE\", \"webView\"=>\"NoResourceEntry-100\"}";
str = str.Replace("\"", "'");
str = str.Replace("=>", ":");
dynamic stuff = Json.Decode(str);
string name = stuff.id;
string address = stuff.textContent;
它會給例外
型「System.TypeInitializationException」的第一次機會異常發生在JsonProject.exe中 'System.Web.Helpers.Json'的類型初始值設定項引發異常。
即使我不保換「與」仍然會拋出異常。
我還沒有使用的Json以前和很新的JSON。我用葫蘆,Android和那裏我得到這個JSON字符串。
您的json無效。 http://jsonlint.com/ – Eser
你可以檢查一下,如果json是否正確地得到「改造」,最終得到解碼的str?通過json驗證器運行它 – BobbyTables