0

I am using JSON.NET to create a JSON string. Basically, I have three List objects that contain information I retrieve from a database. Each list contains information about companies at a certain level of partnership (gold, silver, and bronze). I need my web method to return this JSON string where each partnership level is a sub level of the string, with each of those companies and their information listed within that sub level. I tried using JsonConvert.SerializeObject() for each of my lists. The issue with this is that I need to have sub levels in my JSON string, as seen below:

{
  "gold": {
            //each gold level company
            { "name": name, "logo": logo, ... },
            { "name": name, "logo": logo, ... },
            ...
          },
 "silver": { ... },
 "bronze": { ... }
}

Can someone give me some tips on the best way to achieve this using JSON.NET?

1

1 Answer 1

2
var json  = JsonConvert.SerializeObject(
                new { gold = goldList, silver = silverList, bronze = bronzeList });

where goldList, silverList and bronzeList are your lists.

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

1 Comment

Thanks for your speedy response. I'll give this a shot when I get back to my machine. Do the gold, silver, and bronze in your code represent what gets printed out as the heading for each sub level?

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.