我在寻找如何在邻接模型中为 jqgrid 转换 json 中的 xml 的示例时遇到了麻烦,xml 可以工作,但是在文档中没有 json docs中的示例,所以有人可以指导我在 json 中转换这个 xml 吗? ?,我还在想办法怎么做,帮助真的很感激
这是我的代码:
if ( stristr($_SERVER["HTTP_ACCEPT"],"application/xhtml+xml") ) {
header("Content-type: application/xhtml+xml;charset=utf-8"); } else {
header("Content-type: text/xml;charset=utf-8");
}
if(isset($_REQUEST['nodeid'])==FALSE) {
$node =0;
}
else{
$node = (integer)$_REQUEST["nodeid"];
}
$clsJqGrid = new redCuidadana();
$et = ">";
echo "<?xml version='1.0' encoding='utf-8'?$et\n";
echo "<rows>";
echo "<page>1</page>";
echo "<total>1</total>";
echo "<records>1</records>";
if($node >0) { //check to see which node to load
$wh = 'parent_id='.$node; // parents
//$n_lvl = $n_lvl+1; // we should ouput next level
} else {
//$wh = 'ISNULL(parent_id)';
$wh ='parent_id=0';// roots
}
$mostrarRegistros= $clsJqGrid->mostrarRegistros($wh);
foreach ($mostrarRegistros as $row){
echo "<row>";
echo "<cell>".$row["id_ciudadano"]."</cell>";
echo "<cell>".$row["distrito"]."</cell>";
echo "<cell>".$row["seccion"]."</cell>";
echo "<cell>".$row["rol"]."</cell>";
echo "<cell>".$row["clave_electoral"]."</cell>";
echo "<cell>".$row["nombre"]."</cell>";
echo "<cell>".$row["apaterno"]."</cell>";
echo "<cell>".$row["amaterno"]."</cell>";
echo "<cell>".$row["level"]."</cell>";
echo "<cell><![CDATA[".$row["parent_id"]."]]></cell>";
if($row["level"] == "2"){echo "<cell>"."true"."</cell>";}
else{echo "<cell>".$row["isLeaf"]."</cell>";}
echo "<cell>".$row["expanded"]."</cell>";
echo "</row>";
}
echo "</rows>";
?>
这就是我到目前为止所拥有的
<?php
require_once '../../sesion/model/clsSesion.php';
require_once '../../red_ciudadana/model/modelRedCuidadana.php';
if(isset($_REQUEST['nodeid'])==FALSE) {
$node =0;
}
else{
$node = (integer)$_REQUEST["nodeid"];
}
if($node >0) {
$wh = 'parent_id='.$node;
}
else{
$wh ='parent_id=0';
}
header("Content-type: text/html;charset=utf-8");
$response->total = 1;
$response->page = 1;
$response->records = $count=1;
$i=0;
$clsJqGrid = new redCuidadana();
$mostrarRegistros= $clsJqGrid->mostrarRegistros($wh);
foreach ($mostrarRegistros as $row){
if($row["level"] == "2"){$cosa= "true";}
else{$cosa=$row["isLeaf"];}
$response->rows[$i]['id']=$row["id_ciudadano"];
$row["expanded"];
$response->rows[$i]['cell']= array($row["distrito"],
$row["seccion"],
$row["rol"],
$row["clave_electoral"],
$row["nombre"],
$row["apaterno"],
$row["amaterno"],
$row["level"],
$row["parent_id"],
$cosa,
$row["expanded"]
);
$i++;
}
echo json_encode($response);
?>
但是 jqgrid 没有显示数据,这是我得到的 json
{"total":1,"page":1,"records":1,"rows":[{"id":"1","cell":["01","1001","Coordinador Distrital","ACBJ1975000001","JOSE RAUL","ACEVES","BARRIGA","0","0","false","false"]}]}