Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert JSON String to JSON Object c#

People also ask

How to convert string JSON to JSON object in C#?

Convert String to JSON Object With the JObject. Parse() Function in C# The JObject class inside the Newtonsoft. Json package is used to represent a JSON object in C#.

How to convert a string to object in C#?

Trying to convert a JSON string into an object in C#. Using a really simple test case: JavaScriptSerializer json_serializer = new JavaScriptSerializer(); object routes_list = json_serializer. DeserializeObject("{ \"test\":\"some data\" }");

How to parse a string to JSON in C#?

To parsing the JSON String using JsonConvert. DeserializeObject() which belongs to the JsonConvert class the method called JsonConvert. DeserializeObject() used to convert the JSON string to the C# object. Those objects are created by the JSON string.


JObject defines method Parse for this:

JObject json = JObject.Parse(str);

You might want to refer to Json.NET documentation.


if you don't want or need a typed object try:

using Newtonsoft.Json;
// ...   
dynamic json  = JsonConvert.DeserializeObject(str);

or try for a typed object try:

Foo json  = JsonConvert.DeserializeObject<Foo>(str)

This works

    string str = "{ 'context_name': { 'lower_bound': 'value', 'pper_bound': 'value', 'values': [ 'value1', 'valueN' ] } }";
    JavaScriptSerializer j = new JavaScriptSerializer();
    object a = j.Deserialize(str, typeof(object));

You can try like following:

string output = JsonConvert.SerializeObject(jsonStr);

there's an interesting way to achive another goal which is to have a strongly type class base on json with a very powerfull tools that i used few days ago for first time to translate tradedoubler json result into classes

Is a simple tool: copy your json source paste and in few second you will have a strongly typed class json oriented . In this manner you will use these classes which is more powerful and simply to use.