Deserialize JSON string to c# object Deserialize JSON string to c# object json json

Deserialize JSON string to c# object


I think the JavaScriptSerializer does not create a dynamic object.

So you should define the class first:

class MyObj {    public int arg1 {get;set;}    public int arg2 {get;set;}}

And deserialize that instead of object:

serializer.Deserialize<MyObj>(str);

Not testet, please try.


Use this code:

var result=JsonConvert.DeserializeObject<List<yourObj>>(jsonString);


I believe you are looking for this:

string str = "{\"Arg1\":\"Arg1Value\",\"Arg2\":\"Arg2Value\"}";JavaScriptSerializer serializer1 = new JavaScriptSerializer();object obje = serializer1.Deserialize(str, obj1.GetType());