从json结构获取特定值
问题描述:
我有这个json:
{
"unashamedohio":
{
"id": 107537,
"name": "UnashamedOhio",
"profileIconId": 785,
"revisionDate": 1439997758000,
"summonerLevel": 30
}
}
我想获取名为summonerLevel
的字段.
我尝试将json转换为字符串,然后搜索summonerLevel
,但我知道此解决方案不可行.
I have tried to convert this json to a string and then search for summonerLevel
, but I know that this solution is not okay.
我正在使用Json.NET.
I'm using Json.NET.
答
您可以使用dynamic
关键字
dynamic obj = JsonConvert.DeserializeObject(json);
Console.WriteLine(obj.unashamedohio.summonerLevel);