如何使用关键字作为属性名称?

时间:2021-02-10 21:34:12

I have been serializing anonymous types into json quite successfully until now..

到目前为止,我已经成功地将匿名类型序列化为json。

        dynamic jsObject;

        jsObject = new ExpandoObject();
        jsObject.dataUrl = Controller.Url.Action("loadall", "residuals", new { EditionId = EditionId, Country = Country, ModelYear = ModelYear, MakeId = ModelId, StyleId = style.Id });
        jsObject.id = style.Id;
        jsObject.text = style.Name;
        jsObject.iconCls = "sprite-toolbar-flag-us";
        jsObject.checked = false; // <---<< the problem is here
        jsObject.leaf = true;
        jsObject.IsCustomQuote = style.IsCustomQuote;

        return jsObject;

Is there a workaround? I'm gonna try to serialize a dictionary into a json object if not..

有解决方法吗?如果没有,我会尝试将字典序列化为json对象。

1 个解决方案

#1


5  

You would use the "verbatim" operator @: jsObject.@checked = false;

你可以使用“verbatim”运算符@:jsObject。@ checked = false;

#1


5  

You would use the "verbatim" operator @: jsObject.@checked = false;

你可以使用“verbatim”运算符@:jsObject。@ checked = false;