Does anyone know how to convert a string which contains json into a C# array. I have this which reads the text/json from a webBrowser and stores it into a string.
string docText = webBrowser1.Document.Body.InnerText;
Just need to somehow change that json string into an array. Been looking at Json.NET but I’m not sure if that’s what I need, as I don’t want to change an array into json; but the other way around. Thanks for the help!
just take the string and use the JavaScriptSerializer to deserialize it into a native object. For example, having this json:
You’d need to create a C# class called, for example, Person defined as so:
You can now deserialize the JSON string into an array of Person by doing:
Here’s a link to JavaScriptSerializer documentation.
Note: my code above was not tested but that’s the ideaTested it. Unless you are doing something “exotic”, you should be fine using the JavascriptSerializer.