How can I get this kind of JSON file format from a SQL query? [closed]

…衆ロ難τιáo~ 提交于 2019-12-12 21:23:09

问题


You see, this is my issue:

I need to get a .json file from a SQL query. In order to do that, I use the following ColdFusion .cfm file:

<cfsetting showdebugoutput="no">
<cfheader name="Content-Type" value="application/json">
<cfquery name="GetData" datasource="myDataSource">
    select distinct ap1, ap2, nombre, idcargo
    FROM vlayout_1
    where cct='13DCC0003S'
</cfquery>

<cfoutput>
#SerializeJSON(GetData, true)#
</cfoutput>

Then, I save this file in my localhost server and this is the result:

{"ROWCOUNT":12,"COLUMNS":["AP1","AP2","NOMBRE","IDCARGO"],"DATA":{"AP1":["ALVARADO","BAUTISTA","HERNANDEZ","HERNANDEZ","HERNANDEZ","HERNANDEZ","HERNANDEZ","HERNANDEZ","HERNANDEZ","LORENZO","MARTINEZ","SIXTO"],"AP2":["HERNANDEZ","OSORIO","ALVARADO","ANDRADE","HERNANDEZ","HERNANDEZ","HERNANDEZ","MARTINEZ","QUINTERO","LEON","HERNANDEZ","RAMIREZ"],"NOMBRE":["ALEJANDRO","ANTONIO","LAURA","MA. TERESA","FILOMENA","MARIA GUADALUPE","MARIA LUISA","MARIA MANUELA","CIRILA","JUAN","ROSALBA","EUTIQUIO"],"IDCARGO":[3,3,3,2,3,3,3,3,3,3,1,3]}} 

Once I validate it and format it to JSON through http://jsonlint.com/, this is what I obtain:

{
    "ROWCOUNT": 12,
    "COLUMNS": [
        "AP1",
        "AP2",
        "NOMBRE",
        "IDCARGO"
    ],
    "DATA": {
        "AP1": [
            "ALVARADO",
            "BAUTISTA",
            "HERNANDEZ",
            "HERNANDEZ",
            "HERNANDEZ",
            "HERNANDEZ",
            "HERNANDEZ",
            "HERNANDEZ",
            "HERNANDEZ",
            "LORENZO",
            "MARTINEZ",
            "SIXTO"
        ],
        "AP2": [
            "HERNANDEZ",
            "OSORIO",
            "ALVARADO",
            "ANDRADE",
            "HERNANDEZ",
            "HERNANDEZ",
            "HERNANDEZ",
            "MARTINEZ",
            "QUINTERO",
            "LEON",
            "HERNANDEZ",
            "RAMIREZ"
        ],
        "NOMBRE": [
            "ALEJANDRO",
            "ANTONIO",
            "LAURA",
            "MA. TERESA",
            "FILOMENA",
            "MARIA GUADALUPE",
            "MARIA LUISA",
            "MARIA MANUELA",
            "CIRILA",
            "JUAN",
            "ROSALBA",
            "EUTIQUIO"
        ],
        "IDCARGO": [
            3,
            3,
            3,
            2,
            3,
            3,
            3,
            3,
            3,
            3,
            1,
            3
        ]
    }
}

The issue is that they asked me this .json format:

actasPrimeraAsamblea:{
    [
        ceIntegrante:[
                   {paterno:HERNANDEZ,
                         materno:MARTÍNEZ,
                         nombre:MARÍA GUADALUPE,
                         idcargo:3},
                       {paterno:PÉREZ,
                         materno:ROSALES,
                         nombre:JOSÉ,
                         idcargo:3},
                       {paterno:RAMÍREZ,
                         materno:GONZÁLEZ,
                         nombre:MARIO,
                         idcargo:3}

                     ]
    ]
}

Can you note the differences? My original .json format shows me the View columns, and I need it to be combined.

How can I achieve this?

Thank you in advance, it has been really frustrating.

Sorry for my poor english.

来源:https://stackoverflow.com/questions/16720931/how-can-i-get-this-kind-of-json-file-format-from-a-sql-query

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!