I generate a JSON string in PHP and catch it with httpWebRequest in a .NET windows form application
All works well but I want to use the json.net library to cast that string back to an object (or array).
JsonSerializer serializer = new JsonSerializer();
object result = JsonConvert.DeserializeObject(responseFromServer);
How can i use that object to get the variables from the JSON string?
I’ve been working this out all day and couldn’t find a way to get all values from the JSON string in C#
All help appreciated
If you create a
structin your code that matches the JSON object you can useJsonConvert.DeserializeObject<T>(String)from the Json.NET library. It’s incredibly easy to use and has implementations for pretty much any .NET version.You can also use DataContracts which requires no 3rd party library. With DataContracts there are some intermediate steps and code you need to include, but here is a site with a pretty detailed explanation: Serialization with DataContracts
Here is a link to a question here on SO that involves Json Serialization using DataContracts: SO Question