我们必须为这个简单的json形成哪些特定的类
本文关键字:json 我们 简单 | 更新日期: 2023-09-27 18:25:51
我们如何使用正确的class&成员变量
{
"item": [
{
"id": 12,
"name": "Johnny"
},
{ "id":13,
"name":"mohit"
}
]
}
显然你可以使用Newtonsoft.Json(Json.NET)并使用匿名类型调用方法return。像这样:
var anType = new
{
multiResult = new
{
results = new[]
{
new
{
description = string.Empty,
title = string.Empty,
picUrl = string.Empty,
totalTime = 0,
outerPlayerUrl = string.Empty,
picChoiceUrl = new string[] { "", "" }
}
}
}
};
//get info from JsonString
var tudou = JsonConvert.DeserializeAnonymousType(jsonString, anType);
return VideoDetail.CreateSimpleInstance(DateTime.Now,
tudou.multiResult.results[0].title,
tudou.multiResult.results[0].description,
tudou.multiResult.results[0].picUrl,
tudou.multiResult.results[0].outerPlayerUrl);
}