[SOLVED] Convert JSON String to JSON Object c#

Issue

I have this String stored in my database:

str = "{ "context_name": { "lower_bound": "value", "upper_bound": "value", "values": [ "value1", "valueN" ] } }"

This string is already in the JSON format but I want to convert it into a JObject or JSON Object.

JObject json = new JObject();

I tried the json = (JObject)str; cast but it didn’t work so how can I do it?

Solution

JObject defines method Parse for this:

JObject json = JObject.Parse(str);

You might want to refer to Json.NET documentation.

Answered By – Andrei

Answer Checked By – Terry (BugsFixing Volunteer)

Leave a Reply

Your email address will not be published. Required fields are marked *