如何C#类应对JSON美元符号? [英] How do C# classes deal with dollar signs in JSON?
本文介绍了如何C#类应对JSON美元符号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我收到来自谷歌的数据API 并很多属性名称的开始以$字符(美元符号)。
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从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 no 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屋!
查看全文