开发者

JavaScriptSerializer().Serialize : PascalCase to CamelCase

开发者 https://www.devze.com 2023-02-18 20:51 出处:网络
I have this javascript object var options: { windowTitle: \'....\', windowContentUrl: \'....\', windowHeight: 380,

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 fac开发者_JAVA百科ing this issue of PascalCase to CamelCase that JavaScriptSerializer().Serialize does not handle.

What do you suggest to get around this translation?

Thank you


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 apply JavaScriptSerializer.Serialize() to this Dictionary.
This was good enough for what I needed.

0

精彩评论

暂无评论...
验证码 换一张
取 消