反序列化具有一些以数字开头的属性名称的json

编程入门 行业动态 更新时间:2024-10-26 06:27:50
本文介绍了反序列化具有一些以数字开头的属性名称的json的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

JSON数据如下

[ { "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 您如何为此做一堂课.顺便说一下,我需要所有这些属性,而不仅仅是我提到的那三个属性.

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

本文发布于:2023-11-06 05:30:13,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1562826.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:开头   属性   名称   数字   序列化

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!