XmlAttribute/XmlElement equivalent for JavaScriptSerializer

Is there an equivalent Attribute that can be placed on object Properties in a .NET Class that would perform the equivalent of XmlElement or XmlAttribute? [XmlRoot("objects")] public class MyObjects: List { } [XmlRoot("object")] public class MyObject { [XmlAttribute("name")] public string Name { get; set; } [XmlAttribute("title")] public string Title { get; set; } } This would return XML similar to the following: I would like to have the JavaScriptSerializer, used by the ASP.NET MVC Frameworks 'Json' method in the Controller class: public ActionResult Search() { // code to populate data object return Json(data); } Return the same formatted results, like so: [{"name":"David","title":"Engineer"},{"name":"William","title":"Developer"}] Currently, outputting the object with the Json method, returns: [{"Name":"David"}, "Title":"Engineer"}, {"Name":"William", "Title":"Developer"}] Now, I realize this example is super simplified and the only thing I've done here is change the casing of the property names but in more advanced scenarios I may completely remap the property name to something else ... System.Web.Script.Serialization contains a ScriptIgnoreAttribute attribute, but this simply tells the JavaScriptSerializer to ignore the property when serializing, nothing appears to exist to change the names or format of the actual output however?

以上就是XmlAttribute/XmlElement equivalent for JavaScriptSerializer的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » JavaScript 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准