通过以下 ColdFusion .cfm 文件,我可以获得一个 .json 字符串,它显示了我请求的数据:
json1.cfm
<cfsetting showdebugoutput="no">
<cfheader name="Content-Type" value="application/json">
<cfquery name="GetData" datasource="myDataSource">
select distinct ap1, ap2, nombre, idcargo, idencal, telefono, email, cve_nivel, sexo
FROM vlayout_1
where cct='13DCC0003S'
</cfquery>
<cfoutput>
#SerializeJSON(GetData, false)#
</cfoutput>
一旦我将它上传到我的本地服务器上,这就是结果 .json 字符串:
{"COLUMNS":["AP1","AP2","NOMBRE","IDCARGO","IDENCAL","TELEFONO","EMAIL","CVE_NIVEL","SEXO"],"DATA":[["ALVARADO","HERNANDEZ","ALEJANDRO",3,1,"","",5,"M"],["BAUTISTA","OSORIO","ANTONIO",3,5,"","",6,"M"],["HERNANDEZ","ALVARADO","LAURA",3,5,"","",6,"F"],["HERNANDEZ","ANDRADE","MA. TERESA",2,5,"","",6,"F"],["HERNANDEZ","HERNANDEZ","FILOMENA",3,5,"","",4,""],["HERNANDEZ","HERNANDEZ","FILOMENA",3,5,"","",5,""],["HERNANDEZ","HERNANDEZ","MARIA GUADALUPE",3,5,"","",5,"F"],["HERNANDEZ","HERNANDEZ","MARIA LUISA",3,5,"","",4,"F"],["HERNANDEZ","MARTINEZ","MARIA MANUELA",3,5,"","",4,"F"],["HERNANDEZ","QUINTERO","CIRILA",3,5,"","",5,"F"],["LORENZO","LEON","JUAN",3,5,"","",6,"M"],["MARTINEZ","HERNANDEZ","ROSALBA",1,5,"","",5,"F"],["SIXTO","RAMIREZ","EUTIQUIO",3,5,"","",4,"M"],["SIXTO","RAMIREZ","EUTIQUIO",3,5,"","",5,"M"]]}
在我在http://jsonlint.com/上验证后,我得到了:
{
"COLUMNS": [
"AP1",
"AP2",
"NOMBRE",
"IDCARGO",
"IDENCAL",
"TELEFONO",
"EMAIL",
"CVE_NIVEL",
"SEXO"
],
"DATA": [
[
"ALVARADO",
"HERNANDEZ",
"ALEJANDRO",
3,
1,
"",
"",
5,
"M"
],
[
"BAUTISTA",
"OSORIO",
"ANTONIO",
3,
5,
"",
"",
6,
"M"
],
[
"HERNANDEZ",
"ALVARADO",
"LAURA",
3,
5,
"",
"",
6,
"F"
],
[
"HERNANDEZ",
"ANDRADE",
"MA. TERESA",
2,
5,
"",
"",
6,
"F"
],
[
"HERNANDEZ",
"HERNANDEZ",
"FILOMENA",
3,
5,
"",
"",
4,
""
],
[
"HERNANDEZ",
"HERNANDEZ",
"FILOMENA",
3,
5,
"",
"",
5,
""
],
[
"HERNANDEZ",
"HERNANDEZ",
"MARIA GUADALUPE",
3,
5,
"",
"",
5,
"F"
],
[
"HERNANDEZ",
"HERNANDEZ",
"MARIA LUISA",
3,
5,
"",
"",
4,
"F"
],
[
"HERNANDEZ",
"MARTINEZ",
"MARIA MANUELA",
3,
5,
"",
"",
4,
"F"
],
[
"HERNANDEZ",
"QUINTERO",
"CIRILA",
3,
5,
"",
"",
5,
"F"
],
[
"LORENZO",
"LEON",
"JUAN",
3,
5,
"",
"",
6,
"M"
],
[
"MARTINEZ",
"HERNANDEZ",
"ROSALBA",
1,
5,
"",
"",
5,
"F"
],
[
"SIXTO",
"RAMIREZ",
"EUTIQUIO",
3,
5,
"",
"",
4,
"M"
],
[
"SIXTO",
"RAMIREZ",
"EUTIQUIO",
3,
5,
"",
"",
5,
"M"
]
]
}
问题是,如何在其内容之前显示每个列名?例如:
[
AP1:"SIXTO",
AP2:"RAMIREZ",
NOMBRE:"EUTIQUIO",
IDCARGO:3,
IDENCAL:5,
TELEFONO:"",
EMAIL:"",
CVE_NIVEL:5,
SEXO:"M"
]
非常感谢您!