我从 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 中的美元符号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
读取 XML 时忽略空格Ignore whitespace while reading XML(读取 XML 时忽略空格)
带有检查空元素的 XML 到 LINQXML to LINQ with Checking Null Elements(带有检查空元素的 XML 到 LINQ)
在 C# 中读取带有未闭合标签的 XMLReading XML with unclosed tags in C#(在 C# 中读取带有未闭合标签的 XML)
在 C# 中使用 Html 敏捷性解析表格、单元格Parsing tables, cells with Html agility in C#(在 C# 中使用 Html 敏捷性解析表格、单元格)
使用 LINQ 从 xml 中删除元素delete element from xml using LINQ(使用 LINQ 从 xml 中删除元素)
解析格式错误的 XMLParse malformed XML(解析格式错误的 XML)