Create json from array in PHP -
i have little sql code:
try { $stmt = $conn->prepare("select appid commentroom badgeid=? group appid"); $stmt->execute(array($badgeid)); while ($row = $stmt->fetch(pdo::fetch_assoc)) { $row2[$i][0] = $row['appid']; $i++; } } catch(pdoexception $e) { echo 'error: ' . $e->getmessage(); $server_dir = $_server['http_host'] . rtrim(dirname($_server['php_self']), '/\\'); header('location: http://' . $server_dir); exit(); } when print out result print(json_encode($row2)); following:
[["0000000021"],["0000000037"],["0000000038"],["0000000039"],["0000000128"],["0000000130"]] since have data don't need query database. still need forward in same format java app. when use
$output[] = json_encode($row2); print(json_encode($output)); i different output:
["[[\"0000000021\"],[\"0000000037\"],[\"0000000038\"],[\"0000000039\"],[\"0000000128\"],[\"0000000130\"]]"] i checked few stackoverflow questions didn't find addresses same problem.
you json encoding twice
$output[] = json_encode($row2); print(json_encode($output)); just once:
$output[] = $row2; print(json_encode($output));
Comments
Post a Comment