There could be scenarios in our project wherein we consume a service which returns back a JSON message. These JSON message is infact a stringified version of an object and are recognized as a simple string format by our server side. Decoding them gets difficult at the first shot.
Let me take you through the conversion of a JSON string to a custom C# object here. Its pretty simple!!
#1: ADD the following namespace to your code
MyCustomObject user = jss.Deserialize<MyCustomObject>(jsonResponse);
#4: DEFINE the MyCustomObject class in your code. Ensure that the object structure matches the JSON string format.
public class MyCustomObject
public string myProperty1;
public string myProperty2;
You can then use the Deserialized object “user” and get its properties like:
user.Property1 or user.Property2.
For information on the Serialization of C# object to JSON, you can refer my previous post: