1

This is the model I'm using to deserialize.

C#

public class Info
{
    public string description { get; set; }
    public string[] tags { get; set; }
}

And this is the JSON I want to deserialize.

JSON

{
    "description" : "aeiou",
    "tags" : [ "a", "e", "i", "o" ]
}

When I try to deserealize the JSON object, It throws error. It works when I change the identifier from string[] to just string, but that's not the expected result. I also tried List and didn't work.

2
  • 2
    What is the error? How are you dessrializing it? Commented Nov 15, 2016 at 1:30
  • JavaScriptSerializer js = new JavaScriptSerializer(); and var result = js.Deserialize<Info>(json); Commented Nov 15, 2016 at 3:13

1 Answer 1

2

Try the class like this, don't forget to new up the list first

public class Info
{
    public string description { get; set; }
    public List<string> tags { get; set; }
}
Sign up to request clarification or add additional context in comments.

2 Comments

I don't know what happened, I used List<string> and didn't work. When I got your answer, I tried again and It worked. I gotta say you were right!, thanks so much :)
Don't forget to add the 'set;' bit! That was a silly omission by me that cause a fault in deserialising...

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.