我想在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