在.NET运行时中解析JSON

我想从WebServer获得一些回复。

返回的数据如下所示:

[[3014887,"string1 string","http://sofzh.miximages.com/c%23/b_c9c0625b.jpg",0], [3061529,"string2 string","http://sofzh.miximages.com/c%23/b_320d6d36.jpg",0], [7317649,"string3 string","http://sofzh.miximages.com/c%23/b_a60b3dc2.jpg",0], [12851194,"string4 string","http://sofzh.miximages.com/c%23/b_4e273fa4.jpg",0], [15819606,"string5 string","http://sofzh.miximages.com/c%23/b_66333a8f.jpg",0], [15947248,"string6 string","http://sofzh.miximages.com/c%23/b_920c8b64.jpg",0]] 

我认为是JSON格式,但我无法在我的.Net WinForm应用程序中解析它。 你能提供一些建议或者说明如何做到这一点。

我搜索了JSON.NET库, DataContractJsonSerializer类,但我无法理解如何将它与响应的数据类型粘合在一起……

如果你想解析JSON,那么JSON.net库就是你要去的地方。

你可以像这样使用它:

 var json = @"[[3014887,""string1 string"",""http://sofzh.miximages.com/c%23/b_c9c0625b.jpg"",0], [3061529,""string2 string"",""http://sofzh.miximages.com/c%23/b_320d6d36.jpg"",0], [7317649,""string3 string"",""http://sofzh.miximages.com/c%23/b_a60b3dc2.jpg"",0], [12851194,""string4 string"",""http://sofzh.miximages.com/c%23/b_4e273fa4.jpg"",0], [15819606,""string5 string"",""http://sofzh.miximages.com/c%23/b_66333a8f.jpg"",0], [15947248,""string6 string"",""http://sofzh.miximages.com/c%23/b_920c8b64.jpg"",0]]"; var array = JArray.Parse(json); foreach (var token in array) { Console.WriteLine(token[0]); } 

这样我就可以读取数组的内容了。

WCF命名空间中有JSON(De)序列化( Windows通信支持AJAX集成和JSON )还有非常流行的(更强大的)JSON(de)序列化库JSON.Net