I'm retrieving json from a public api and converting it into a dynamic object using JsonFx.
我正在从一个公共api中检索json,并使用JsonFx将其转换为动态对象。
JsonFx.Json.JsonReader reader = new JsonFx.Json.JsonReader();
dynamic response = reader.Read(jsonAsString);
The json contains a property named return. e.g.
json包含一个名为return的属性。如。
{"result":"success","return":{"high":{"value":"3.85001","value_int":"385001","display":"3.85001\u00a0\u20ac","currency":"EUR"}}
JsonFx creates the dynamic object fine and I can also debug into it and see the values. The problem is when I try to reference the property in my code the compiler complains:
JsonFx很好地创建了动态对象,我也可以在其中调试并查看值。问题是当我试图引用我代码中的属性时,编译器会抱怨:
response.return.high.currency
Identifier expected; 'return' is a keyword
How can I reference the return property without the compiler complaining?
如何引用return属性而不引起编译器的抱怨?
1 个解决方案
#1
15
Try response.@return.high.currency
.
.@return.high.currency尝试回应。
You need to append @
at the begining of any field wich name is the same as C# keywords.
您需要在任何字段名称的开头添加@,这与c#关键字相同。
#1
15
Try response.@return.high.currency
.
.@return.high.currency尝试回应。
You need to append @
at the begining of any field wich name is the same as C# keywords.
您需要在任何字段名称的开头添加@,这与c#关键字相同。