本文介绍了格式化JSON对象数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 任何人都知道如何修改控制器中的JSON对象,以便按照指定的顺序显示数据,如第二张图片所示。 {表:[ {中央CDC:[Sengkang West GRC,def ] }, {东北CDC:[Pasir Ris - Punggol GRC,Tampines GRC] }, 使用系统; 使用 System.Collections.Generic; 使用 System.Data; 使用 System.Linq; 使用 System.Net; 使用 System.Net.Http; 使用 System.Threading.Tasks; 使用 System.Web.Http; 使用 System.Web.Http.Description; 使用 System.Web.Http.Results; 使用 System.Web.Mvc; 命名空间 Prototype3.Controllers { public class GAROController:ApiController { Database_Access_Data.db dblayer = new Database_Access_Data.db (); [System.Web.Http.HttpGet] [System.Web.Http.Route( api / GARO / GetGAROList)] public DataSet CheckLockedOut() { DataSet ds = dblayer.GetGAROList(); return ds; } } } public DataSet GetGAROList() { SqlCommand com = new SqlCommand( GetCDC,con); com.CommandType = CommandType.StoredProcedure; SqlDataAdapter da = new SqlDataAdapter(com); DataSet ds = new DataSet(); da.Fill(ds); return ds; } / * *****对象:StoredProcedure [dbo]。[GetCDC]脚本日期: 4/12/2018 4:33:23 PM ****** / SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO ALTER PROCEDURE [dbo]。[GetCDC] AS BEGIN SELECT E.Name AS ED_N ame,displayname = STUFF(( SELECT DISTINCT ' ,' + D.Name FROM ElectoralDivision D WHERE E.ID = D.GAROID FOR XML PATH(' )), 1 , 2 ,' ') From GARO E GROUP BY E.ID, E.Name END 我尝试了什么: 尝试研究格式化JSON数据的任何解决方案但无济于事。解决方案 我似乎无法找到您所指的图片,但是,如果您尝试将JSON对象格式化为所需格式,我建议您查看inti JSON.Net :如何使用C#在.NET中获取格式化JSON? - 堆栈溢出 [ ^ ] Anyone knows how can i modify the JSON Object in the controller such that it would display the data in a specified order which is shown on the 2nd picture.{ "Table": [ { "Central CDC":["Sengkang West GRC", "def"] }, { "North-East CDC": ["Pasir Ris - Punggol GRC", "Tampines GRC"] }, using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.Net; using System.Net.Http; using System.Threading.Tasks; using System.Web.Http; using System.Web.Http.Description; using System.Web.Http.Results; using System.Web.Mvc; namespace Prototype3.Controllers { public class GAROController : ApiController{ Database_Access_Data.db dblayer = new Database_Access_Data.db(); [System.Web.Http.HttpGet] [System.Web.Http.Route("api/GARO/GetGAROList")] public DataSet CheckLockedOut() { DataSet ds = dblayer.GetGAROList(); return ds; }} }public DataSet GetGAROList(){ SqlCommand com = new SqlCommand("GetCDC", con); com.CommandType = CommandType.StoredProcedure; SqlDataAdapter da = new SqlDataAdapter(com); DataSet ds = new DataSet(); da.Fill(ds); return ds;}/****** Object: StoredProcedure [dbo].[GetCDC] Script Date:4/12/2018 4:33:23 PM ******/SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO ALTER PROCEDURE [dbo].[GetCDC] AS BEGIN SELECT E.Name AS ED_Name, displayname = STUFF((SELECT DISTINCT ', ' + D.Name FROM ElectoralDivision D WHERE E.ID = D.GAROID FOR XML PATH('')), 1, 2, '') From GARO E GROUP BY E.ID,E.Name ENDWhat I have tried:Tried to researching for any solution in formatting the JSON Data but to no avail. 解决方案 这篇关于格式化JSON对象数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 08-01 13:59