0

I'm using C#.Net and am trying to parse out some JSON.

I have this JSON that I retrieve. I've tried to use JavaScriptSerliazer but cannot figure out the correct structure.

What is the best way to parse this JSON to get each array (first, second, third, etc)?

{
"first":["A","B"],
"second":["C","D"],
"third":["E","F","G","H","I"],
"fourth":["J","K","L","M","N"]
}
R Saudlach
  • 388
  • 1
  • 5
  • 24
  • 3
    Possible duplicate of [deserializing JSON to .net object using NewtonSoft (or linq to json maybe?)](http://stackoverflow.com/questions/4749639/deserializing-json-to-net-object-using-newtonsoft-or-linq-to-json-maybe) – Timo Salomäki Aug 31 '16 at 17:22
  • 6
    Possible duplicate of [Parse JSON in JavaScript?](http://stackoverflow.com/questions/4935632/parse-json-in-javascript) – Seth Flowers Aug 31 '16 at 17:23

1 Answers1

5

Create a class like this:

public class RootObject
{
   public List<string> first { get; set; }
   public List<string> second { get; set; }
   public List<string> third { get; set; }
   public List<string> fourth { get; set; }
}

Courtesy: json2charp

Use NewtonSoft Json:

RootObject tmp = JsonConvert.DeserializeObject<RootObject>(json);

Then manipulate tmp object as you want

Henrique Forlani
  • 1,325
  • 9
  • 22