0
helo我已經努力了在頁面中打印randamoly的json值,這裏有4個類別,我用javascript做的事情是找到包含許多對象的json數組的長度,然後採用類型id,因爲它在所有數組中都很常見,以確定它們是否屬於0,1,2,3類別,然後打印json數組中的所有元素等等,這裏我想創建表對於每個類別並將所有相應的ID推送到表格行。插入json解析的值到表
var txt = '<?php echo $response ?>';
//alert(txt);
//var jsonData = eval ("(" + txt + ")");
var jsonData = JSON.parse(txt);
for (var i = 0; i < jsonData.account_detail.length; i++) {
var counter = jsonData.account_detail[i];
//console.log(counter.counter_name);
//alert(counter.type);
document.write("<table border="0" width="500>">")
if(counter.type=="0")
{
document.write(counter.building_name);
document.write(counter.org_name);
document.write(counter.user_name);
document.write(counter.name);
document.write(counter.loc_name);
document.write(counter.email_id);
document.write(counter.password);
}
if(counter.type=="1")
{
document.write(counter.user_name);
document.write(counter.name);
document.write(counter.password);
document.write(counter.email_id);
}
if(counter.type=="2")
{
document.write(counter.building_name);
document.write(counter.org_name);
document.write(counter.user_name);
document.write(counter.opr_code);
document.write(counter.name);
document.write(counter.loc_name);
document.write(counter.email_id);
document.write(counter.password);
}
if(counter.type=="3")
{
document.write(counter.building_name);
document.write(counter.org_name);
document.write(counter.machine_type);
document.write(counter.activate_status);
document.write(counter.machine_name);
document.write(counter.entrance_exit_name);
document.write(counter.entrance_or_exit);
document.write(counter.loc_name);
document.write(counter.activation_code);
}
}
document.write("</table>")
有你用JS這樣做的理由。你可以使用PHP的方法json_decode()來獲得一個PHP數組,然後foreach()循環它來建立html表格 – fullybaked 2013-04-26 09:17:16
我不是很好的PHP,這就是我使用javascript的原因 – user2322631 2013-04-26 09:18:36
你的
回答
試試這個:
來源
2013-04-26 09:22:10
每行中'td'元素的數目並不相等。 – 2013-04-26 09:23:47
是的,但每個表只包含一行.. – 2013-04-26 09:25:49
沒有運氣,現在解析結果也沒有出現。感謝您給予嘗試 – user2322631 2013-04-26 09:32:57
相關問題