11

i have this class

public class Image
{
    public string url { get; set; }
    public string url_40px { get; set; }
    public string url_50px { get; set; }
}

public class Category
{
    public List<int> ancestor_ids { get; set; }
    public int parent_id { get; set; }
    public List<object> children_ids { get; set; }
    public string nodename { get; set; }
    public int num_parts { get; set; }
    public List<Image> images { get; set; }
    public string __class__ { get; set; }
    public int id { get; set; }
}

and i deserialize it like this

retObject = JsonConvert.DeserializeObject(Of Category)(jsonResp)

but for a list of category returned, how do i convert to List<Category>? thanks

1
  • 2
    have you tried JsonConvert.DeserializeObject(Of List<Category>)(jsonResp) Commented Jun 27, 2012 at 6:56

1 Answer 1

23

The type parameter for DeserializeObject has to be List<Category> instead of Category.

In C# it would be JsonConvert.DeserializeObject<List<Category>>(json)

And In VB.Net it would be JsonConvert.DeserializeObject(Of List(Of Category))(json)

Sign up to request clarification or add additional context in comments.

3 Comments

hello, what is its an array off category?
You can use any type for the DeserializeObject method. Newtonsoft tries to deserialize the specified type and (in case of success) returns it. So you may also write DeserializeObject(Of Category[])(json). (I don't know VB so maybe you have to write the array type different)
The VB for this would be JsonConvert.DeserializeObject(Of List(Of Category))(json)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.