我正在研究從JSON格式的Battlelog API中收集數據的應用程序。 這是「玩家」類的樣子在JSONL:JsonConvert.DeserializeObject <Object>(字符串)不返回任何東西
{
"player":{
"id":173521680,
"game":"bf4",
"plat":"pc",
"name":"1ApRiL",
"tag":"",
"dateCheck":1386842250248,
"dateUpdate":1386827475171,
"dateCreate":1383962204725,
"lastDay":"20131206",
"country":"DE",
"countryName":"Germany",
"rank":{
"nr":9,
"imgLarge":"bf4/ranks/r9.png",
"img":"r9",
"name":"Lance Corporal IV",
"needed":140000,
"next":{
"nr":10,
"img":"r10",
"name":"Lance Corporal V",
"needed":168000,
"curr":165309,
"relNeeded":28000,
"relCurr":25309,
"relProg":90.38928571428572
}
},
"score":165309,
"timePlayed":25740,
"uId":"2832660339132815718",
"uName":"1ApRiL",
"uGava":"7222ff803a0a67404aa082b22ff3fa5b",
"udCreate":1319474914000,
"blPlayer":"http://battlelog.battlefield.com/bf4/soldier/1ApRiL/stats/173521680/pc/",
"blUser":"http://battlelog.battlefield.com/bf4/user/1ApRiL/",
"editable":false,
"viewable":true,
"adminable":false,
"linked":false
}
}
這是我的C#類Player
樣子:
public class Player
{
public int id { get; set; }
public string game { get; set; }
public string plat { get; set; }
public string name { get; set; }
public string tag { get; set; }
public long dateCheck { get; set; }
public long dateUpdate { get; set; }
public long dateCreate { get; set; }
public string lastDay { get; set; }
public string country { get; set; }
public object countryName { get; set; }
public Rank rank { get; set; }
public int score { get; set; }
public int timePlayed { get; set; }
public string uId { get; set; }
public string uName { get; set; }
public string uGava { get; set; }
public long udCreate { get; set; }
public string blPlayer { get; set; }
public string blUser { get; set; }
public bool editable { get; set; }
public bool viewable { get; set; }
public bool adminable { get; set; }
public bool linked { get; set; }
}
最後:這是我嘗試反序列化(數據是JSON數據):
Player p = JsonConvert.DeserializeObject<Player>(data);
然而,當我嘗試運行它只是不返回任何的方法,它留下的所有領域的空白,即使我沒有得到任何例外或錯誤。
我希望這是我錯過的小而簡單的事情,但我無法弄清楚什麼。
感謝提前:)
那是確切的JSON你的要求得到什麼?因爲它缺少一個關閉'}'。我不認爲這是問題,但至少應該檢查一下。 –
@Chris Mantle他說這只是一個粘貼錯誤,這就是我刪除我的答案的原因:) – albusshin