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);
2

3 Answers 3

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();
}
Sign up to request clarification or add additional context in comments.

Comments

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);

Comments

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>();

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.