0

I want to parse JSON string. Problem is with writing classes.how should i write classes like table structure or according to JSON string?

Format: JSON
    Content: 
    {
        success: 0,
        message: “”,
        token :””,
        data:
{
"User":{
                        "UserID": 1212,
                        "UserEmail": "[email protected]",
                        "UserNameLast": "abc",
                        "UserNameFirst": "xyz",
                        "UserRoleID": 1,
                        "UserRole": "Sales Executive",
                        "UserPhone": "1212",
                },
"Managers":[{
                            "UserID":1,
                            "UserEmail": "[email protected]",
                            "LastName": "qwe",
                            "FirstName": "qwe",
                            "UserRole": "Manager",
                            "UserPhone": "222222",
                        },
        {
                            "UserID":2,
                            "UserEmail": "[email protected]",
                            "LastName": "eee",
                            "FirstName": "eee",
                            "UserRole": "General Manager",
                            "UserPhone": "33333",
                        }
]
}
}

Table structure is different than json string.

3 Answers 3

1

I think you need it into C# classes If yes then
Use http://jsonlint.com/ to check if it is valid Json then http://json2csharp.com/ to convert it into C# classes. I think it is easiest way.

Sign up to request clarification or add additional context in comments.

Comments

0

You can go ahead and define a class based on the JSON say "Class User" and then have getters and setters for the class and then while parsing the JSON you can set the field of the class.

1 Comment

ok.but as shown in above json string i have insert 1record(User) in some table at the same time 2 records in another table(managers) for example 1 request send to its 2 manager.request table is different and request forwarded to table table is different.
0

This is how your model should look like to be serialized in like the json you supplied.

 public class UserDetailViewModel
{
    public User User { get; set; }

    public List<Manager> Managers { get; set; }
}

And then return the object like Json(userDetailViewModelInstance).

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.