$sql = "SELECT * FROM `scripts` LIMIT 0, 30 ";
$result = mysql_query($sql) or die ('Error updating database: ' . mysql_error());
$json = array();
if(mysql_num_rows($result)) {
while($row=mysql_fetch_row($result)) {
$json['table data'][]=$row;
}
}
$encoded = json_encode($json);
echo $encoded;
這是我的輸出:在PHP中,我從mySQL編碼了一個JSON數組,我該如何使用它?解碼?
{"table data":[["1","test","30","13"],["2","test2","40","14"]]}
如何訪問數組,其數組的數組的單個物品?我是否先解碼它?
你想在哪裏使用它? – itachi 2013-04-11 21:46:11
爲什麼你首先編碼它? – showdev 2013-04-11 21:47:59
歡迎來到Stack Overflow!在附註中; [請不要在新代碼中使用'mysql_ *'函數](http://stackoverflow.com/q/12859942/1190388)。他們不再被維護,並[正式棄用](https://wiki.php.net/rfc/mysql_deprecation)。看到紅色框?改爲了解準備好的語句,然後使用[tag:PDO]或[tag:MySQLi]。 – hjpotter92 2013-04-11 21:48:19