嘿,伙计们,我有这个json文件(摘录):https://hastebin.com/uzifiteqol.json我已经创建了一个响应命令的不和谐机器人,其中一个命令是*card (卡名)这个json文件提供了所有卡的统计信息,但是我想让用户根据idname (卡名)来访问LVL9的统计信息,例如:*card箭头这应该会给用户显示在JSON中的LVL9箭头的面积伤害,但是我不确定如何访问这个统计信息。这是我到目前为止所知道的:
string jsonString = File.ReadAllText("/Users/me/Desktop/cardstatsfile.json");这就是json文件在我的电脑(mac)上的位置,我不确定如何从那里开始,我想我需要JToken.parse并解析文件来查找"idname“或用户指定的卡。提前感谢!
编辑:澄清:因为有75张牌,所以我想通过提供idname来获得elixircost、稀有度等的值,以及所有LVL9的统计数据。或者我需要重新格式化JSON才能做到这一点?
发布于 2017-08-01 14:22:44
反序列化到一个POCO,如下所示,然后执行操作
public class Stat
{
public int level { get; set; }
public int areaDamage { get; set; }
public int crownTowerDamage { get; set; }
public int? hitpoints { get; set; }
public int? dps { get; set; }
}
public class RootObject
{
public string _id { get; set; }
public string idName { get; set; }
public string rarity { get; set; }
public string type { get; set; }
public string name { get; set; }
public string description { get; set; }
public int arena { get; set; }
public int elixirCost { get; set; }
public int order { get; set; }
public int __v { get; set; }
public int radius { get; set; }
public string target { get; set; }
public List<Stat> stats { get; set; }
public string statsDate { get; set; }
public int? hitSpeed { get; set; }
public int? speed { get; set; }
public int? deployTime { get; set; }
public double? range { get; set; }
public int? count { get; set; }
public string transport { get; set; }
}发布于 2017-08-01 14:09:27
编写一些POCO类,以对象形式存储反序列化后的数据。使用Newtonsoft执行反序列化任务。JsonConvert类是您的朋友。
https://stackoverflow.com/questions/45430088
复制相似问题