I am querying a table that return to fields(message_type & percentage). I use PHP to encode the json data, here is how i do it
$json = array();
while ($row = odbc_fetch_array($rs)) {
$json[][] = $row;
}
echo json_encode($json);
output :
[ [ { "message_type" : "bullying",
"percentage" : "60"
} ],
[ { "message_type" : "cheating",
"percentage" : " 14"
} ],
[ { "message_type" : "Stress",
"percentage" : "16"
} ],
[ { "message_type" : "Gang",
"percentage" : "7"
} ]
]
As you can see json_encode function is adding curly braces, quotes and the object key name.
What I want is to parse the json as two dimensional array only, here is the desired output:
[
["bullying", 60],
["harrassment", 9],
["cheating", 14],
["Stress", 16],
["Gang", 7]
]
I also tried to encode it manually but I could not get the result I need.
$json[][]
--- why[][]
? – zerkms Apr 9 '13 at 23:22$json[] = array_values($row);
– DaveRandom Apr 9 '13 at 23:23