我对json的编码字符串有问题。我正在做一个谷歌饼图。图表将充满来自数据库的数据。 Google图表需要json格式的数据。json的编码字符串
下面是一个字符串它应该是什么样子的例子。现在我有一个动态“组装”字符串与数据库中的数据的问题。 JSON_encode是不够的,它必须在格式这样的字符串与行和行! 请帮忙。
<?php
$db=new DB();
$db->connect();
$db->selectBase();
$rows = array();
$sth=$db->st_glede_na_tip() or die(mysql_error());
while($r = mysql_fetch_assoc($sth)) {
$rows[] = $r;
}
$string= '{
"cols": [
{"id":"","label":"Content","pattern":"","type":"string"},
{"id":"","label":"Slices","pattern":"","type":"number"}
],
"rows": [
{"c":[{"v":"Books"},{"v":3}]},
{"c":[{"v":"Video"},{"v":1}]},
{"c":[{"v":"Audio"},{"v":1}]},
{"c":[{"v":"Movie"},{"v":1}]},
]
}';
echo $string;
?>
你可以使用json_encode()函数...? – 2012-07-16 08:12:17
“json_encode”有什么问题? – poncha 2012-07-16 08:12:24
谷歌图表需要独特的格式和行和行。 – 2012-07-16 08:14:36