Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3760112
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T10:25:16+00:00 2026-05-19T10:25:16+00:00

Can anyone tell me how I can deserialize an object that contains multiple attributes?

  • 0

Can anyone tell me how I can deserialize an object that contains multiple attributes?

Given the scenario below, the code works fine.

public ActionResult Index()
{
    string json = @"{""name"": ""Person 2"",""email"": ""example@example.com""}";

    var emp = JsonConvert.DeserializeObject<Person>(json);
    Response.Write(emp.name + emp.email);
    return View();
}

public class Person
{
    public string name { get; set; }
    public string email { get; set; }
}

But what do I have to do if the array contains multiple items, e.g

string json = @"{""data"": [{""name"": ""Person 1"",""email"": ""test@test.com""},{""name"": ""Person 2"",""email"": ""example@example.com""}]}";

Thanks in advance

The answers already given below were perfect for the problem I asked, but now I’ve gone one step ahead. Can anyone advise on what I’d need to do if the json had an array in it e.g. the addition of an address in?

{
    "data": [
        {
            "name": "Person 1",
            "email": "test@test.com",
            "address": {
                "address1": "my address 1",
                "address2": "my address 2" 
            } 
        },
        {
            "name": "Person 2",
            "email": "example@example.com",
            "address": {
                "address1": "my address 1",
                "address2": "my address 2" 
            } 
        } 
    ] 
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T10:25:17+00:00Added an answer on May 19, 2026 at 10:25 am

    Something like this has worked for me in the past:

    JObject o = JObject.Parse(json); // This would be the string you defined above
    // The next line should yield a List<> of Person objects...
    List<Person> list = JsonConvert.DeserializeObject<List<Person>>(o["data"].ToString());
    

    You might want to decorate your Person object as follows:

    [JsonObject(MemberSerialization.OptIn)]
    public class Person
    {
        [JsonProperty]
        public string name{get;set;}
        [JsonProperty]
        public string email{get;set;}
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can anyone tell me what exactly does this Java code do? SecureRandom random =
Can anyone tell me if there are RDBMSs that allow me to create a
Can anyone tell me why this code would throw an undefined is not a
Can anyone tell me why this works: $(#test1 td).click(function(event) { $(#test1).addClass(tableRowSelected); }); $(#test2 td).click(function(event)
Can anyone tell me ifwe can access the permissions that each application that a
Can anyone tell me why this code crashes with SIGABRT unrecognised selector sent to
can anyone tell me why this animation isn't starting? i've tried putting code in
Can anyone tell me that when we scroll or move mkmapview then according to
Can anyone tell me what is going wrong with this code? I tried to
Can anyone tell me why the following code might not cycle through the array

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.