JSON parsing in .NET runtime

I want to get a response from WebServer.

The returned data is as follows:

[[3014887,"string1 string","http://num60.webservice.com/u3014887/b_c9c0625b.jpg",0], [3061529,"string2 string","http://num879.webservice.com/u3061529/b_320d6d36.jpg",0], [7317649,"string3 string","http://num1233.webservice.com/u7317649/b_a60b3dc2.jpg",0], [12851194,"string4 string","http://num843.webservice.com/u12851194/b_4e273fa4.jpg",0], [15819606,"string5 string","http://num9782.webservice.com/u15819606/b_66333a8f.jpg",0], [15947248,"string6 string","http://num1500.webservice.com/u15947248/b_920c8b64.jpg",0]] 

I think it is in JSON , but I could not parse it in my .Net WinForm application. Can you provide some tips or examples on how to do this.

I googled about the JSON.NET library, DataContractJsonSerializer class, but I couldn't figure out how to glue all this together with the response data type ...

+4
source share
2 answers

If you want to parse JSON, then it will be JSON.net .

You can use it as follows:

 var json = @"[[3014887,""string1 string"",""http://num60.webservice.com/u3014887/b_c9c0625b.jpg"",0], [3061529,""string2 string"",""http://num879.webservice.com/u3061529/b_320d6d36.jpg"",0], [7317649,""string3 string"",""http://num1233.webservice.com/u7317649/b_a60b3dc2.jpg"",0], [12851194,""string4 string"",""http://num843.webservice.com/u12851194/b_4e273fa4.jpg"",0], [15819606,""string5 string"",""http://num9782.webservice.com/u15819606/b_66333a8f.jpg"",0], [15947248,""string6 string"",""http://num1500.webservice.com/u15947248/b_920c8b64.jpg"",0]]"; var array = JArray.Parse(json); foreach (var token in array) { Console.WriteLine(token[0]); } 

That way, I could read the contents of your array.

+14
source

In the WCF namespace, there is JSON (De) serialization ( Windows support for AJAX and JSON integration ) there is also a very popular (more powerful) JSON (de) JSON.Net serialization library

0
source

Source: https://habr.com/ru/post/1300160/


All Articles