I am having troubles in finding examples in how to convert this xml in json for the jqgrid in adjacency model, the xml works, but in the docs there are no examples in json docs, so can someone guide me in convert this xml in json??, I am still figuring out how to do it, help really apreciated
this is my code:
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>";
?>
this is what I have so far
<?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);
?>
But the jqgrid is not displaying data, this is the json I get
{"total":1,"page":1,"records":1,"rows":[{"id":"1","cell":["01","1001","Coordinador Distrital","ACBJ1975000001","JOSE RAUL","ACEVES","BARRIGA","0","0","false","false"]}]}
I don’t know php, but this is how I do it in c# (ASP.NET MVC3): This is for an autoloading tree, not load tree at once.
Action method:
Method where the list of TreeNodes is built up:
TreeNode Class:
Sample JSON (note our ids are GUIDS):
Maybe it will be easy for you to convert.