1

I have the following JSOn I need to parse:

{"items":[{"dict":"es","words":[{"word":"car","id":"3487"},{"word":"dog","id":"443"},{"word":"plane","id":"1171"}]},{"dict":"fr","words":[{"word":"house","id":"134"}]}]} 

Using JavaScriptSerializer, how could I iterate first through each dict and then retrieve the id of each word?

4
  • 6
    Have you tried anything? Commented Nov 19, 2013 at 12:33
  • There are various JSon (de)serializers out there, you shouldn't have any trouble finding one... Commented Nov 19, 2013 at 12:35
  • Do you have any model that will hold this for deserialization? Commented Nov 19, 2013 at 12:35
  • @scheien I don't know where to start besides making my own parser. I know how to do this in PHP but I'm not that familiar with ASP Commented Nov 19, 2013 at 12:58

1 Answer 1

1

make anonymouse type, acording your json, for example:

var result = new[] {new {action = "", value = false}}; // put your item structure here
var list   = JsonConvert.DeserializeObject(myJson, result.GetType());

then you might want to itterate through. For example:

foreach (dynamic val in  ((dynamic) list)) { ...
Sign up to request clarification or add additional context in comments.

2 Comments

How can I set the item structure in result ?
var result = new[] { new { dict = new KeyValuePair<string, List<KeyValuePair<string, string>>>()}};

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.