Json将单个对象字符串转换为List <string>

时间:2016-04-02 15:00:31

标签: c# json json.net

我很难将一个简单的json对象变成List

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

不工作

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

如何将json字符串解析为List?

2 个答案:

答案 0 :(得分:4)

您需要指定List<string>作为DeserializeObject的类型参数:

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

答案 1 :(得分: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 );