当前位置:  开发笔记 > 编程语言 > 正文

C#从反序列化的json对象获取值

如何解决《C#从反序列化的json对象获取值》经验,为你挑选了0个好方法。

我目前正在使用Newtonsoft.Json nuget数据包使用以下代码反序列化json字符串:

var data = (JObject)JsonConvert.DeserializeObject(json);

现在,我收到以下格式的对象:

{{  "meta": {    "rap": 2098,    "count": 5  },  "data": [    {      "name": "Gold Tetramino of Mastery",      "rap": 735,      "uaid": "16601901",      "link": "https://www.roblox.com/Gold-Tetramino-of-Mastery-item?id=5786047",      "img": "https://t4.rbxcdn.com/081337d7ea86e6a406512aaa83bbcdeb",      "serial": "---",      "count": 1    },    {      "name": "Silver Tetramino of Accomplishment",      "rap": 385,      "uaid": "16601900",      "link": "https://www.roblox.com/Silver-Tetramino-of-Accomplishment-item?id=5786026",      "img": "https://t1.rbxcdn.com/60da69cd76f8dad979326f63f4a5b657",      "serial": "---",      "count": 1    },    {      "name": "Subzero Ski Specs",      "rap": 370,      "uaid": "155175547",      "link": "https://www.roblox.com/Subzero-Ski-Specs-item?id=19644587",      "img": "https://t4.rbxcdn.com/8ead2b0418ef418c7650d34103d39b6d",      "serial": "---",      "count": 1    },    {      "name": "Rusty Tetramino of Competence",      "rap": 319,      "uaid": "16601899",      "link": "https://www.roblox.com/Rusty-Tetramino-of-Competence-item?id=5785985",      "img": "https://t2.rbxcdn.com/968ad11ee2f4ee0861ae511c419148c8",      "serial": "---",      "count": 1    },    {      "name": "Bluesteel Egg of Genius",      "rap": 289,      "uaid": "16601902",      "link": "https://www.roblox.com/Bluesteel-Egg-of-Genius-item?id=1533893",      "img": "https://t7.rbxcdn.com/48bf59fe531dd1ff155e455367e52e73",      "serial": "---",      "count": 1    }  ]}}

现在,我试图从中获得以下价值:

"rap": 2098,

我只需要2098,并且一直在尝试以下代码:

string rap = data["rap"].Value();

但是可惜这是行不通的。有谁知道如何获得价值?

推荐阅读
个性2402852463
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有