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 中的美元符号?
				
        
 
            
        基础教程推荐
- 首先创建代码,多对多,关联表中的附加字段 2022-01-01
 - 错误“此流不支持搜索操作"在 C# 中 2022-01-01
 - 是否可以在 asp classic 和 asp.net 之间共享会话状态 2022-01-01
 - 如何动态获取文本框中datagridview列的总和 2022-01-01
 - 经典 Asp 中的 ResolveUrl/Url.Content 等效项 2022-01-01
 - 将事件 TextChanged 分配给表单中的所有文本框 2022-01-01
 - 从 VS 2017 .NET Core 项目的发布目录中排除文件 2022-01-01
 - 全局 ASAX - 获取服务器名称 2022-01-01
 - JSON.NET 中基于属性的类型解析 2022-01-01
 - 在 VS2010 中的 Post Build 事件中将 bin 文件复制到物 2022-01-01
 
    	
    	
    	
    	
    	
    	
    	
    	
						
						
						
						
						
				
				
				
				