我希望使用某种带有引入JSON数据的变量的重复循环。
我正在使用Codeignitor和jquery。
由于
答案 0 :(得分:1)
如果您想要将JSON转换为PHP变量或对象,我认为此代码将解释它:
<强>代码:强>
<?
// here is an array
$myarray = array(
'animal' => 'dog',
'plant' => 'tree',
'anotherArray' => array ('some' => 'data'),
);
// print out the array to show what it looks like
print_r($myarray);
// convert the array to json
$jsonArray = json_encode($myarray);
// print out the json data
print $jsonArray.'\n';
// convert the json data back into a PHP array
$phpArray = json_decode($jsonArray);
// print out the array that went from PHP to JSON, and back to PHP again
print_r($phpArray);
<强>输出:强>
Array
(
[animal] => dog
[plant] => tree
[anotherArray] => Array
(
[some] => data
)
)
{"animal":"dog","plant":"tree","anotherArray":{"some":"data"}}
stdClass Object
(
[animal] => dog
[plant] => tree
[anotherArray] => stdClass Object
(
[some] => data
)
)