我有一个JSON数组,如下所示:
{ "images" :
[
{
"pid":0,
"image_title":"this is title of image1"
},
{
"pid":1,
"image_title":"this is title of image2"
},
{
"pid":2,
"image_title":"this is title of image3",
}
]
}
如何将其转换为List <>?
我尝试以下操作:
public async Task<Tuple<Models.User_Data, Models.Response>>
test([FromBody]JObject _jo)
{
List<Image> _images = _jo["images"].ToList<Image>();
...
}
但是它给了我:“ jtoken不包含tolist的定义”
答案 0 :(得分:1)
GOTCHA!
List<Image> _images = JsonConvert.DeserializeObject<List<Image>>(_jo["images"].ToString());
答案 1 :(得分:0)
尝试
JObject obj = JObject.Parse("here pass your JsonString");
var jarr = obj["images"].Value<JArray>();
List<Image> lst = jarr.ToObject<List<Image>>();