我试图遵循
JavaScript和C#中的命名约定.当来回传递JSONized数据时,这会导致一些有趣的问题.当我访问x / y坐标客户端时,我希望该属性为小写,但服务器端为大写.
注意:
public class ComponentDiagrampolygon { public List<System.Drawing.Point> Vertices { get; set; } public ComponentDiagrampolygon() { Vertices = new List<System.Drawing.Point>(); } } public JsonResult VerticesToJsonpolygon(int componentID) { PlanViewComponent planViewComponent = PlanViewServices.GetComponentsForPlanView(componentID,SessionManager.Default.User.UserName,"image/png"); ComponentDiagram componentDiagram = new ComponentDiagram(); componentDiagram.LoadComponent(planViewComponent,Guid.NewGuid()); List<ComponentDiagrampolygon> polygons = new List<ComponentDiagrampolygon>(); if (componentDiagram.ComponentVertices.Any()) { ComponentDiagrampolygon polygon = new ComponentDiagrampolygon(); componentDiagram.ComponentVertices.ForEach(vertice => polygon.Vertices.Add(vertice)); polygons.Add(polygon); } return Json(polygons,JsonRequestBehavior.AllowGet); }
解决方法
您可以通过投射到新的匿名类型来作弊:
var projected = polygons.Select(p => new { Vertices = p.Vertices.Select(v => new { x = v.X,y = v.Y }) }); return Json(projected,JsonRequestBehavior.AllowGet);
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。