I have a JSON array that I would like to loop through to create a table.
TITLE etc would of course be the headings of the table and the associated data placed underneath.
JSON Result from PHP file
[
{
"TITLE":"Empire Burlesque",
"ARTIST":"Bob Dylan",
"COUNTRY":"USA",
"COMPANY":"Columbia",
"PRICE":"10.90",
"YEAR":"1985"
},{
"TITLE":"Picture book",
"ARTIST":"Simply Red",
"COUNTRY":"EU",
"COMPANY":"Elektra",
"PRICE":"7.20",
"YEAR":"1985"
}
]
PHP
$filterText = "1985";//$_REQUEST["text"];
$filename = "xml/xml_cd.xml";
$filterHeading = "YEAR";
$filterText = "1985";//$_REQUEST["text"];
$file = simplexml_load_file($filename);
$children = $file->children();
$firstchild = $children[0];
$node = $firstchild->getName();
$result = $file->xpath('//'.$node.'['. $filterHeading . '/text()="'.$filterText.'"]');
$jsondata = json_encode($result,true);
print_r($jsondata);
I believe the solution should be in javascript but can't quite work out how to tackle the problem, being new to JSON and JAVASCRIPT.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…