![](/img/trans.png)
[英]JSON Parsing to retrieve and display the values of attributes in a textbox (WIndows Phone 8)
[英]Display JSON Values into labels or textbox
我正在嘗試弄清楚如何將JSON文件直接顯示到標簽或文本框中,這是我到目前為止所獲得的。
JSON文件
"players": [
{
"account_id": 85000810,
"name": "bb",
"hero_id": 0,
"team": 2
},
{
"account_id": 181829645,
"name": "Lobby: 0/0 Waifubot",
"hero_id": 0,
"team": 2
},
{
"account_id": 79119406,
"name": "Hitoshura",
"hero_id": 83,
"team": 1
},
{
"account_id": 48981143,
"name": "Mercury",
"hero_id": 93,
"team": 1
},
{
"account_id": 54661761,
"name": "Knockin' on Heaven's Door",
"hero_id": 9,
"team": 0
},
{
"account_id": 17124907,
"name": "xX_DoMiNaNt_DoMiNiC_Xx ◣◢)┌∩┐",
"hero_id": 57,
"team": 0
},
我希望將其名稱顯示在我的label1,label2,label3,label4等中。
這是我的代碼:
LiveLeagues.LiveLeagues liveGames =JsonConvert.DeserializeObject<LiveLeagues.LiveLeagues>(response.Content.ReadAsStringAsync().Result);
foreach (var leagues in liveGames.Result.games)
{
foreach (var players in leagues.players)
{
if (players.team == radiant_team)
{
AddRadiantPlayers(players.name, players.account_id, players.hero_id);
}
if (players.team == dire_team)
{
AddDirePlayers(players.name, players.account_id, players.hero_id);
}
}
}
目前,我正在將它們的名稱顯示在gridview中,然后從中將值傳遞到標簽中,使用不可見的gridview作為橋梁是很討厭的。
您的json
與以下C# Type
類似:
public class Player
{
public int account_id { get; set; }
public string name { get; set; }
public int hero_id { get; set; }
public int team { get; set; }
}
public class Container
{
public List<Player> players { get; set; }
}
然后var d = JsonConvert.DeserializeObject<Container>("yourjson").players;
您可以遍歷players
並做精彩的事情。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.