我正在尝试将此关联数组传递给 JavaScript:
Array ( [0] => Array ( [topicid] => 38 [topic] => Dad ) [1] => Array ( [topicid] => 6 [topic] => What did you eat? ) [2] => Array ( [topicid] => 4 [topic] => What have you done? ) [3] => Array ( [topicid] => 43 [topic] => He ) [4] => Array ( [topicid] => 28 [topic] => I doubt it ) [5] => Array ( [topicid] => 10 [topic] => What made you feel good ) [6] => Array ( [topicid] => 12 [topic] => Say to yourself ) [7] => Array ( [topicid] => 29 [topic] => I doubt myself ) )
在 PHP 文件中:
$topicsjson=json_encode($topics);
echo "<script>var topicsjson = $topicsjson; </script>";
在 JavaScript 文件中:
document.write(topicsjson);
它给了我这个结果:
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
我在这里错过了什么吗?