0

I want to generate C# class from this (JSON DATA) but http://json2csharp.com/ can't generate the C# class. The JSON should be valid (http://jsonlint.com/). Can you help me?

And when I create the class form JSON I only use something like this:

MyNewClass test = ser.Deserialize<MyNewClass>(response);
nawfal
  • 66,413
  • 54
  • 311
  • 354
Pepa Zapletal
  • 2,739
  • 3
  • 34
  • 67

3 Answers3

1

You don't need any class since your json is List<List<string>>

var result = new JavaScriptSerializer().Deserialize<List<List<string>>>(json);

or using Json.Net

var result = JsonConvert.DeserializeObject<List<List<string>>>(json);

That is all....

foreach (var list in result)
{
    foreach (var item in list)
        Console.Write(item + " ");
    Console.WriteLine();
}
I4V
  • 34,225
  • 4
  • 65
  • 78
0

You need to create your C# class. So, for example;

public class Wrapper
{   
    public List<CustomObject> Data { get; set; }
}

public class CustomObject 
{ 
    public string Id {get;set;}
    public string Name {get;set;}
}

and then deserialize with System.Web.Script.Serialization.JavaScriptSerializer()

Wrapper wrapper = new System.Web.Script.Serialization.JavaScriptSerializer().Deserialize<Wrapper>(json);
Sam Leach
  • 12,362
  • 8
  • 42
  • 72
0

The easyest and simplest way in 2 steps without any 3rth party libraries

1- go to http://json2csharp.com/ and let the generator to create your c# classes

2-

HttpResponseMessage response = await client.GetAsync(Url);    
YourJSonClass obj = await response.Content.ReadAsAsync<YourJSonClass>();
LeonardoX
  • 789
  • 10
  • 26