Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

SOLVED: Parsing JSON with C# [duplicate]

Manky Fox:

This question already has an answer here:

  • How can I deserialize JSON to a simple Dictionary in ASP.NET? 20 answers

Currently I have a Json body that I would like to deserialize into a list of objects in C#. The JSON looks very similar to this:


{
"123": {
"id": "123",
"description": "Element 1",
...
},
"456": {
"id": "456",
"description": "Element 2",
...
},
...
}

My current structure is as follows:


class FooList
{
public Dictionary Foos { get; set; }
}

class Foo
{
public int id { get; set; }
public string description { get; set; }
}

and utilising NewtonSoft I am attempting the following:


// json = string representation of json data
JsonConvert.DeserializeObject(json);

This doesn't work. I have managed to deserialize single instances of Foo with the previous line of code, but I am unsure how I can handle the process when the JSON doesn't have a set root element and comprises a list of objects with dynamic root elements.

Apologies if this question has been answered previously, either I am using incorrect language to describe the issue or the answer doesn't seem to exist.

Edit: "This doesn't work" equates to returning an instance of FooList with Foos as null.



Posted in S.E.F
via StackOverflow & StackExchange Atomic Web Robots
This Question have been answered
HERE


This post first appeared on Stack Solved, please read the originial post: here

Share the post

SOLVED: Parsing JSON with C# [duplicate]

×

Subscribe to Stack Solved

Get updates delivered right to your inbox!

Thank you for your subscription

×