如何从SQL查询中获取此类JSON文件格式?

时间:2013-05-23 18:06:36

标签: sql xml json coldfusion

你知道,这是我的问题:

我需要从SQL查询中获取.json文件。为此,我使用以下ColdFusion .cfm文件:

<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>

然后,我将此文件保存在我的localhost服务器中,这就是结果:

{"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]}} 

一旦我验证它并通过http://jsonlint.com/将其格式化为JSON,这就是我获得的:

{
    "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
        ]
    }
}

问题是他们问我.json格式:

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}

                     ]
    ]
}

你能注意到这些差异吗?我原来的.json格式显示了View列,我需要将它组合起来。

我怎样才能做到这一点?

提前谢谢你,这真的令人沮丧。

抱歉我的英语很差。

0 个答案:

没有答案