R Saudlach
R Saudlach

Reputation: 388

Parsing JSON in C# .net

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"]
}

Upvotes: 0

Views: 518

Answers (1)

Henrique Forlani
Henrique Forlani

Reputation: 1353

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

Upvotes: 5

Related Questions