关于json动态拼接响应数据
在EasyUI http://www.jeasyui.com/demo/main/get_users.php 响应数据如下格式:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 | { "total" : "11" , "rows" : [ { "id" : "50528" , "firstname" : "wrerw" , "lastname" : "erwerw" , "phone" : "" , "email" : "" }, { "id" : "50529" , "firstname" : "asdf" , "lastname" : "asdf" , "phone" : "" , "email" : "asdf@asdf.c" }, { "id" : "50532" , "firstname" : "sdfdsfds" , "lastname" : "fsdfdsfagcdga" , "phone" : "" , "email" : "" }, { "id" : "50533" , "firstname" : "ewfg" , "lastname" : "gdfgdfgdfg" , "phone" : "" , "email" : "" }, { "id" : "50534" , "firstname" : "sagfg" , "lastname" : "wwGSGSG" , "phone" : "" , "email" : "" }, { "id" : "50535" , "firstname" : "sa" , "lastname" : "sa" , "phone" : "sa" , "email" : "sa@dssddsd.dsd" }, { "id" : "50536" , "firstname" : "asdf" , "lastname" : "asdf" , "phone" : "asdf" , "email" : "asdf@asdf.com" }, { "id" : "50537" , "firstname" : "s" , "lastname" : "sdf" , "phone" : "" , "email" : "" }, { "id" : "50538" , "firstname" : "33" , "lastname" : "sd" , "phone" : "13445" , "email" : "131@131.com" }, { "id" : "50539" , "firstname" : "1" , "lastname" : "1" , "phone" : "1" , "email" : "1@qq.com" } ] } |
//C#后台动态拼接
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | DataTable dt = new DataTable(); StringBuilder str = new StringBuilder(); str.Append( "{\"total\":\"" + dt.Rows.Count + "\",\"rows\":[" ); for ( int i = 0; i < dt.Rows.Count; i++) { //就是这些\ 转义很容易造成错误 str.Append( "{\"FtyVendorCode\":\"" + dt.Rows[i][ "CustID" ].ToString() + "\",\"CompanyName\":\"" + dt.Rows[i][ "CompanyName" ].ToString() + "\",\"Contact\":\"" + dt.Rows[i][ "ContactPerson" ].ToString() + "\",\"EMail\":\"" + dt.Rows[i][ "ContactEmail" ].ToString() + "\",\"Phone\":\"" + dt.Rows[i][ "ContactPhone" ].ToString() + "\"" ); } str.ToString().TrimEnd( new char [] { ',' }); str.Append( "]}" ); context.Response.Write(str.ToString()); |
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步