Assaf Zigdon Assaf Zigdon - 4 months ago 33
JSON Question

C# .net how to deserialize complex object of JSON

I have a JSON string and I need some help to deserialize it.

nothing worked for me.. this is the JSON

{
"response": [
{
"loopa": "81ED1A646S894309CA1746FD6B57E5BB46EC18D1FAff",

"drupa": "D4492C3CCE7D6F839B2BASD2F08577F89A27B4ff",

"images": [

{

"report": {

"nemo": "unknown"

},

"status": "rock",

"id": "7e6ffe36e-8789e-4c235-87044-56378f08m30df",

"market": 1

},

{

"report": {

"nemo": "unknown"

},

"status": "rock",

"id": "e50e99df3-59563-45673-afj79e-e3f47504sb55e2",

"market": 1

}

]

}

]

}


i have an example of the classes but i don't have to use those classes, i don't mind using some other classes.
these are the classes:

public class Report
{
public string nemo { get; set; }
}

public class Image
{
public Report report { get; set; }
public string status { get; set; }
public string id { get; set; }
public int market { get; set; }
}

public class Response
{
public string loopa { get; set; }
public string drupa{ get; set; }
public Image[] images { get; set; }
}

public class RootObject
{
public Response[] response { get; set; }
}


I want to mention that i have Newtonsoft.Json already so i can use some functions from there.

how can I do this?
thanks.

Answer

I am using like this in my code and it's working fine

below is a piece of code which you need to write

using System.Web.Script.Serialization;

JavaScriptSerializer oJS = new JavaScriptSerializer();
RootObject oRootObject = new RootObject();
oRootObject = oJS.Deserialize<RootObject>(Your JSon String);