.Net 4: How to reference a dynamic object with property named “return”

大憨熊 提交于 2019-12-04 02:58:05

问题


I'm retrieving json from a public api and converting it into a dynamic object using JsonFx.

JsonFx.Json.JsonReader reader = new JsonFx.Json.JsonReader();
dynamic response = reader.Read(jsonAsString);

The json contains a property named return. e.g.

{"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:

response.return.high.currency
Identifier expected; 'return' is a keyword  

How can I reference the return property without the compiler complaining?


回答1:


Try response.@return.high.currency.

You need to append @ at the begining of any field wich name is the same as C# keywords.



来源:https://stackoverflow.com/questions/7579248/net-4-how-to-reference-a-dynamic-object-with-property-named-return

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!