我正在寻找使用JSP,JSON和MYSQL作为数据源的Google图表。
我检查了但是我没有得到任何有用的例子......我得到了一些PHP示例,这也是有效的......但是我需要在JSP中....我试过一些例子,但它的给出错误,如....
未找到列
谷歌图表的Json格式:
PHP代码:
<?php include_once 'settings/config2.php';
$sth = mysql_query("SELECT * FROM captcha");
$rows = array();
$flag = true;
$table = array();
$table['cols'] = array(
array('label' => 'word', 'type' => 'string'),
array('label' => 'cap', 'type' => 'number'),
array('label' => 'id', 'type' => 'number')
);
$rows = array();
while($r = mysql_fetch_assoc($sth)) {
$temp = array();
$temp[] = array('v' => (string) $r['word']);
$temp[] = array('v' => (int) $r['captcha_time']);
$temp[] = array('v' => (int) $r['captcha_id']);
$rows[] = array('c' => $temp);
}
$table['rows'] = $rows;
$jsonTable = json_encode($table);
echo $jsonTable;
?>
输出:
{"cols":[{"label":"word","type":"string"},{"label":"cap","type":"number"},
"rows":[
{"c":[{"v":"zmQUtTxm"},{"v":1382242835}]},{"c":[{"v":"6QCCtIt0"},{"v":1382242846}]},
{"c":[{"v":"OVHqIrHH"},{"v":1382242923}]},{"c":[{"v":"PvvaKdwS"},{"v":1382242933}]},
{"c":[{"v":"O9Gh4oVl"},{"v":1382243745}]},{"c":[{"v":"NI6hsJKa"},{"v":1382243785}]},
{"c":[{"v":"3Mcc6sPC"},{"v":1382245480}]},{"c":[{"v":"1wDmZlXv"},{"v":1382245612}]}]}
我在JSP中需要相同的东西。
我在这里得到了一些json格式:
How do I create a multidimensional HashMap or Hashtable in JSP / Java and convert it to a JSON object?
但我需要以上格式...
谢谢