0

I'm using a Json string from another system. It looks something like this:

{
  "BoolValue": true,
  "Inventory": {
    "Item1": {
      "id": "1",
      "name": "Item One"
    },
    "Item2": {
      "id": "2",
      "name": "Item Two"
    },
    "Item3": {
      "id": "2",
      "name": "Item Three"
    }
  }
}

How would I deserialize the "Item" objects to a List? I know it's easy then the json uses an array for "Inventory": [] but how will I do it when it's just object after object under the Inventory property?

2
  • are you looking for what classes you'll need, or how to deserialize into your classes? Commented Jan 23, 2014 at 18:21
  • 3
    The values shown under each item won't work for a List; they have a key/value structure. You'll need a hash table of some type like a Dictionary<T>. Either way, in order to deserialize you'll need a class definition for that. Commented Jan 23, 2014 at 18:25

1 Answer 1

3

If I'm understanding correctly, you'll need a class setup like this:

public class Results {
    public bool BoolValue { get; set; }
    public Dictionary<string, Item> Inventory { get; set; }
}

public class Item {
    public string id { get; set; }
    public string name { get; set; }
}
Sign up to request clarification or add additional context in comments.

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.