C# 类如何处理 JSON 中的美元符号? [英] How do C# classes deal with dollar signs in JSON?

查看:31
本文介绍了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 中的美元符号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆