![](/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.