Heim >Backend-Entwicklung >PHP-Tutorial >怎么把JSON的多维数组转换成JS的多维数组
如何把JSON的多维数组转换成JS的多维数组
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--><?php $arr1=array("a","b","c"); $arr2=array( array("a1","a2","a3"), array("b1","b2","b3"), array("c1","c2","c3") ); $arr3=array( array( array("a11","a12","a13"), array("a21","a22","a23"), array("a31","a32","a33") ), array( array("b11","b12","b13"), array("b21","b22","b23"), array("b31","b32","b33") ), array( array("c11","c12","c13"), array("c21","c22","c23"), array("c31","c32","c33") ) ); $parm=$_GET["parm"]; switch ($parm){ case "arr1": echo json_encode($arr1); break; case "arr2": echo json_encode($arr2); break; case "arr3": echo json_encode($arr3); break; } ?>
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->$.getJSON("../php/json.php?parm=arr2", function(json){//中间应该怎么写});
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->var arr1=["a","b","c"]; var arr2=[ ["a1","a2","a3"], ["b1","b2","b3"], ["c1","c2","c3"] ]; var arr3=[ [ ["a11","a12","a13"], ["a21","a22","a23"], ["a31","a32","a33"] ], [ ["b11","b12","b13"], ["b21","b22","b23"], ["b31","b32","b33"] ], [ ["c11","c12","c13"], ["c21","c22","c23"], ["c31","c32","c33"] ] ];