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
  • 70,104
  • 56
  • 326
  • 368
Pepa Zapletal
  • 2,879
  • 3
  • 39
  • 69

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,891
  • 6
  • 67
  • 79
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,746
  • 9
  • 45
  • 73
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
  • 1,113
  • 14
  • 31