我很难将一个简单的json对象变成List
var returnedJson = ["applicant", "recruiter", "team"];
不工作
List<string> list = (List<string>)JsonConvert.DeserializeObject(returnedJson);
如何将json字符串解析为List?
答案 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 );