1

I am having a hard time getting a simple json object into a List

var returnedJson = ["applicant", "recruiter", "team"];

NOT WORKING

List<string> list = (List<string>)JsonConvert.DeserializeObject(returnedJson);

How can I parse the json string into a List?

1
  • In future, rather than just "not working" can you say what you observe vs what you expected? Is it a compile-time error, an exception, something else? Please edit your post to make it clearer for future readers. Commented Apr 2, 2016 at 15:10

2 Answers 2

4

You need to specify List<string> as the type argument to DeserializeObject:

var list = JsonConvert.DeserializeObject<List<string>>(returnedJson);
Sign up to request clarification or add additional context in comments.

Comments

1
//DeserializeObject<T>() needs type T. 
//Thus you've to specify result type in place of T no an explicit cast is required.
List<string> list = JsonConvert.DeserializeObject<List<string>>(returnedJson );

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.