How do C# classes deal with dollar signs in JSON?(C# 类如何处理 JSON 中的美元符号?)
问题描述
我从 Google 的数据 API 获取 JSON 供稿并且很多属性名称都以 $ 字符(美元符号)开头.
I'm getting a JSON feed from Google's data API and a lot of the property names start with a $ character (dollar sign).
我的问题是我不能创建一个变量名以美元符号开头的 C# 类,这是语言不允许的.我正在使用 JSON.NET from Newtonsoft 将 JSON 转换为 C# 对象.我该如何解决这个问题?
My problem is that I can't create a C# class with a variable name starting with a dollar sign, it's not allowed by the language. I'm using JSON.NET from Newtonsoft to convert JSON to C# objects. How can I get around this problem?
推荐答案
您可以尝试使用 [JsonProperty] 属性来指定名称:
You could try using the [JsonProperty] attribute to specify the name:
[JsonProperty(PropertyName = "$someName")]
public string SomeName { get; set; }
这篇关于C# 类如何处理 JSON 中的美元符号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:C# 类如何处理 JSON 中的美元符号?
基础教程推荐
- 如何使用 .Net 检查 Active Directory 服务器是否已启动并正在运行? 2022-01-01
- 我应该在后面的代码中直接使用 Linq To SQL 还是使 2022-01-01
- Moq It.Is<>不匹配 2022-01-01
- 如果有人提交恶意软件Nuget包怎么办? 2022-01-01
- 禁止输入少量字符,例如'<'、'&a 2022-01-01
- 当值可以是对象或空数组时反序列化 JSON 2022-01-01
- Azure Functions:CosmosDBTrigger 未在 Visual Studio 中触发 2022-01-01
- C# 从 List<List<int>> 中删除重 2022-01-01
- WPF 模态进度窗口 2022-01-01
- .NET SerialPort DataReceived 事件未触发 2022-01-01
