zoukankan      html  css  js  c++  java
  • 关于json动态拼接响应数据

    在EasyUI http://www.jeasyui.com/demo/main/get_users.php 响应数据如下格式:

    {
        "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#后台动态拼接

     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());
    

      

  • 相关阅读:
    用jmeter通过ssl验证访问https
    github jekyll主题
    JMeter中返回Json数据的处理方法
    使用Nginx实现反向代理
    Antd 表格 -- 自定义合并行处理
    Go语言--第8章 包(package)
    GO语言 -- 第7章 接口(INTEFACE)
    GO语言--第6章 结构体
    PHP--相关扩展安装
    Go语言--第5章 函数
  • 原文地址:https://www.cnblogs.com/yzenet/p/3464667.html
Copyright © 2011-2022 走看看