【发布时间】:2014-05-06 22:38:15
【问题描述】:
我正在从一个游戏中向 3 个不同的用户发出服务器请求。
结果我得到了这个 JSON 字符串:
{
"d4r1o": {
"id": 1040806,
"name": "D4R1O",
"profileIconId": 596,
"revisionDate": 1399366400000,
"summonerLevel": 30
},
"snnovox": {
"id": 65728,
"name": "SN Novox",
"profileIconId": 548,
"revisionDate": 1399369344000,
"summonerLevel": 30
},
"gmbecken": {
"id": 421545,
"name": "GM Becken",
"profileIconId": 26,
"revisionDate": 1399160360000,
"summonerLevel": 30
}
}
所以为了反序列化这个字符串,我有这些类
public class RootObject
{
public SummonerDto d4r1o { get; set; }
public SummonerDto snnovox { get; set; }
public SummonerDto gmbecken { get; set; }
}
public class SummonerDto
{
public int id { get; set; }
public string name { get; set; }
public int profileIconId { get; set; }
public long revisionDate { get; set; }
public int summonerLevel { get; set; }
}
这很好用,但是如果用户想对自己的用户名提出请求怎么办,例如:snyucax
{"snyucax": {
"id": 48985,
"name": "SN YucaX",
"profileIconId": 504,
"revisionDate": 1399257043000,
"summonerLevel": 30
}}
有没有办法在 RootObject 类中只创建一个对象,让我可以使用任何用户名,而不必将该名称指定为对象?
【问题讨论】: