aaa
Table of Contents
1.Generate C# classes from JSON online web tool.
Generate C# classes from JSON Class
{
"unique_id": "computer_download_speed",
"name": "电脑 下载速度",
"state_topic": "home/computer/status/download_speed",
"unit_of_measurement": "bytes/s",
"device_class": "data_rate",
"value_template": "{{ value }}",
"device": {
"identifiers": ["computer_unique_identifier"],
"name": "电脑",
"manufacturer": "期望氢气球",
"model": "PC-Model",
"sw_version": "1.0"
}
}
C# classes
// Root myDeserializedClass = JsonConvert.DeserializeObject<Root>(myJsonResponse);
public class Device
{
public List<string> identifiers { get; set; }
public string name { get; set; }
public string manufacturer { get; set; }
public string model { get; set; }
public string sw_version { get; set; }
}
public class Root
{
public string unique_id { get; set; }
public string name { get; set; }
public string state_topic { get; set; }
public string unit_of_measurement { get; set; }
public string device_class { get; set; }
public string value_template { get; set; }
public Device device { get; set; }
}
2.use vs2017,first copy json ,then execute below. Visual Studio 2017 (with ASP.NET and Web Tools 2012.2 RC installed) supports this natively. Visual Studio 2017 onwards have this built-in. .
3.How can I format JSON document in Visual Studio ?
You could copy your code into a blank JSON file using the menus. I'm using Microsoft Visual Studio Community 2022.
File -->New-->File-->Web-->JSON File
JSON Formatter
json formatter 插件是一款能格式化json代码,使得json代码页面变得便于阅读的chrome json格式化插件,安装了这款插件后需要为该插件添加允许访问文件网址的权限以自动允许插件功能,之后该插件将会为你打开的json网页文件自动执行代码格式化、树状折叠以及缩进等功能。
https://mp.weixin.qq.com/s/aoEmwFwBwZReXCEUPKJC1A
https://github.com/callumlocke/json-formatter