是否可以使用 JSON.NET 反序列化此 json?
"players": {
"0": {
"success": 1,
"name": "xsusususdd"
},
"1": {
"success": 1,
"name": "bleeps"
},
..."n": {
"success": 1,
"name": "bloops"
}
}
我正在使用的第 3 方 Web 服务不返回数组,而是返回由任意数量的嵌套对象组成的对象。
我从以下方面开始:
public class Players
{
public Player 0 {get;set;} //cant name the Player 0
public Player 1 {get;set;} //cant name the Player 1
public List<Players> players {get;set;} //doesn't work because it isn't being returned as an array
}
public class Player
{
public string success { get; set; }
public string name { get; set; }
}
var URL = new WebClient().DownloadString("http://webservice");
Players result = JsonConvert.DeserializeObject<Players>(URL);