不工作我有一個數組sessionValue是如下:在循環在JavaScript
document.write(sessionValue);
Array ([Finance] => Array ([0] => 0 [1] => 3 [2] => 0 [3] => 0 [4] => 1)
[Human resources] => Array ([0] => 1 [1] => 5 [2] => 1 [3] => 0 [4] => 0)
[Infrastructure] => Array ([0] => 0 [1] => 3 [2] => 1 [3] => 0 [4] => 0)) 1
使用檢索會話值和打印數組中的JavaScript頁面... in循環:
JSpage .js文件
sessionValue = '<?php echo json_encode($_SESSION["Count"]); ?>';
document.write(sessionValue);
document.write("<br />");
for(var s1 in sessionValue) {
for(var s in sessionValue[s1]) {
document.write(s);
}}
給出輸出:
{"Finance":[0,3,0,0,1],"Human resources":[1,5,1,0,0],"Infrastructure":[0,3,1,0,0]}
0000000000000000000000000000000000000000000000000000000000000000000000000000000000
而且如果for ... in循環寫入如下:
for(var s1 in sessionValue) {
for(var s in sessionValue[s1]) {
document.write(sessionValue[s1][s]);
document.write("<br />");
}}
給出輸出:
{"Finance":[0,3,0,0,1],"Human resources":[1,5,1,0,0],"Infrastructure":[0,3,1,0,0]}
{
"
F
i
n
a
n
c
e
"
:
[
0
,
3
,
,並繼續打印整個array.I相信它認爲它作爲字符串連雖然我用json_encode()。
我想檢索關鍵,例如。財務和內部數組值。如何解決這個問題?
你在sessionValue設置爲一個字符串在這裏:'sessionValue ='<?php echo json_encode($ _ SESSION [「Count」]); ?>';'你需要把它作爲一個對象正確輸出。只要刪除單引號。 – ManoDestra