Deserialize json that has some property name starting with a number(反序列化具有以数字开头的某些属性名称的 json)
问题描述
JSON 数据如下所示
JSON data looks like this
[
{
"market_id": "21",
"coin": "DarkCoin",
"code": "DRK",
"exchange": "BTC",
"last_price": "0.01777975",
"yesterday_price": "0.01770278",
"change": "+0.43",
"24hhigh": "0.01800280",
"24hlow": "0.01752015",
"24hvol": "404.202",
"top_bid": "0.01777975",
"top_ask": "0.01790000"
}
]
请注意此处的这 3 个属性 24high、24hhlow 和 24hvol你如何为此上课.顺便说一句,我需要所有这些属性,而不仅仅是我提到的那 3 个属性.
Notice these 3 properties here 24high, 24hhlow, and 24hvol how do you make a class for that. I need all those properties by the way, not just those 3 properties I mentioned.
推荐答案
你应该使用 JSON.NET 或类似的库来提供一些更高级的反序列化选项.使用 JSON.NET,您只需添加 JsonProperty 属性并指定出现在结果 JSON 中的自定义名称.示例如下:
You should use JSON.NET or similar library that offers some more advanced options of deserialization. With JSON.NET all you need is adding JsonProperty attribute and specify its custom name that appears in resulting JSON. Here is the example:
public class MyClass
{
[JsonProperty(PropertyName = "24hhigh")]
public string Highest { get; set; }
...
现在反序列化:
string jsonData = ...
MyClass deserializedMyClass = JsonConvert.DeserializeObject<MyClass>(jsonData);
这篇关于反序列化具有以数字开头的某些属性名称的 json的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:反序列化具有以数字开头的某些属性名称的 json
基础教程推荐
- Moq It.Is<>不匹配 2022-01-01
- 当值可以是对象或空数组时反序列化 JSON 2022-01-01
- WPF 模态进度窗口 2022-01-01
- 如果有人提交恶意软件Nuget包怎么办? 2022-01-01
- .NET SerialPort DataReceived 事件未触发 2022-01-01
- Azure Functions:CosmosDBTrigger 未在 Visual Studio 中触发 2022-01-01
- 我应该在后面的代码中直接使用 Linq To SQL 还是使 2022-01-01
- 禁止输入少量字符,例如'<'、'&a 2022-01-01
- C# 从 List<List<int>> 中删除重 2022-01-01
- 如何使用 .Net 检查 Active Directory 服务器是否已启动并正在运行? 2022-01-01
