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

时间:2010-12-16 00:55:06

标签: c# json anonymous-types

到目前为止,我已经非常成功地将匿名类型序列化为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;

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

1 个答案:

答案 0 :(得分:5)

您可以使用“逐字”运算符@jsObject.@checked = false;