Click here to Skip to main content
15,885,216 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
My json object is like this :

{
"ddlItems":[{"QuestionId":"2","AnswerId":"2","AnswerOption":"1"},{"QuestionId":"3","AnswerId":"2","AnswerOption":"4"}],

"txtItems":[{"QuestionId":"1","AnswerId":"1","AnswerText":"asd"}],

"categoryId":"5"
}


can anyone plz let me know how to deserialize this into c# object

thanks !!
Posted
Updated 26-Nov-13 4:42am
v2

1 solution

This is what http://json2csharp.com/ created:

C#
public class DdlItem
{
    public string QuestionId { get; set; }
    public string AnswerId { get; set; }
    public string AnswerOption { get; set; }
}

public class TxtItem
{
    public string QuestionId { get; set; }
    public string AnswerId { get; set; }
    public string AnswerText { get; set; }
}

public class RootObject
{
    public List<DdlItem> ddlItems { get; set; }
    public List<TxtItem> txtItems { get; set; }
    public string categoryId { get; set; }
}


After that you can use following code:

XML
using System.Web.Script.Serialization;

JavaScriptSerializer oJS = new JavaScriptSerializer();
RootObject oRootObject = new RootObject();
oRootObject = oJS.Deserialize<RootObject>(Your JSon String);
 
Share this answer
 
Comments
naveend915 27-Nov-13 8:27am    
Thanks a lot ...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900