JavaScriptSerializer().Serialize:PascalCase 到 CamelCase
我有这个 javascript 对象
var options:
{
windowTitle : '....',
windowContentUrl : '....',
windowHeight : 380,
windowWidth : 480
}
我有这个 C# 类
public class JsonDialogViewModel
{
public string WindowTitle { get; set; }
public string WindowContentUrl { get; set; }
public double WindowHeight { get; set; }
public double WindowWidth { get; set; }
}
你看,我的符号是 C# 中的 PascalCase,我的 Javascript 是 CamelCase。 这是通常的约定。
我正在使用 JavaScriptSerializer().Serialize 序列化我的 C# 对象并在我的 Javascript 代码中使用它。
然而,我面临着 JavaScriptSerializer().Serialize 无法处理的 PascalCase 到 CamelCase 的问题。
您建议如何绕过此翻译?
谢谢
I have this javascript object
var options:
{
windowTitle : '....',
windowContentUrl : '....',
windowHeight : 380,
windowWidth : 480
}
And I have this C# class
public class JsonDialogViewModel
{
public string WindowTitle { get; set; }
public string WindowContentUrl { get; set; }
public double WindowHeight { get; set; }
public double WindowWidth { get; set; }
}
And you see, my notation is PascalCase in C# and my Javascript is CamelCase.
That the usual convention.
I am using JavaScriptSerializer().Serialize to serialize my C# object and use it in my Javascript code.
I am however facing this issue of PascalCase to CamelCase that JavaScriptSerializer().Serialize does not handle.
What do you suggest to get around this translation?
Thank you
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我能找到的最好的解决方案是有一个方法来接收要序列化的对象,根据对象的属性生成一个
Dictionary
,然后应用JavaScriptSerializer.Serialize ()
到此词典。这足以满足我的需要。
The best solution I could find was to have a method that receives the object to be serialized, generates a
Dictionary<string, object>
based on the properties of the object and then applyJavaScriptSerializer.Serialize()
to this Dictionary.This was good enough for what I needed.