<?php
$con=mysqli_connect("localhost","root","");
mysqli_select_db($con,"qstatslite")or die("error");
$q = mysqli_query($con,"SELECT * FROM queue_stats ORDER BY queue_stats_id DESC LIMIT 20");
$return_arr = array();
while ($row = mysqli_fetch_array($q)) {
$row_array['queue_stats_id'] = $row['queue_stats_id'];
$row_array['datetime'] = $row['datetime'];
$row_array['qname'] = $row['qname'];
$row_array['qagent'] = $row['qagent'];
$row_array['qevent'] = $row['qevent'];
$row_array['info1'] = $row['info1'];
$row_array['info2'] = $row['info2'];
$row_array['info3'] = $row['info3'];
array_push($return_arr,$row_array);
}
echo json_encode($return_arr);
?>
輸出:JSON解析到Android使用TableLayout或ListView
[{"queue_stats_id":"198191","datetime":"2016-06-16 17:32:32","qname":"5","qagent":"50","qevent":"7","info1":"2","info2":"91","info3":"1"},{"queue_stats_id":"198190","datetime":"2016-06-16 17:31:01","qname":"5","qagent":"50","qevent":"10","info1":"2","info2":"1466069459.6496","info3":"1"},{"queue_stats_id":"198188","datetime":"2016-06-16 16:28:41","qname":"5","qagent":"53","qevent":"8","info1":"2","info2":"113","info3":"1"},{"queue_stats_id":"198187","datetime":"2016-06-16 16:26:48","qname":"5","qagent":"53","qevent":"10","info1":"2","info2":"1466065606.6445","info3":"1"},{"queue_stats_id":"198185","datetime":"2016-06-16 15:47:25","qname":"5","qagent":"50","qevent":"7","info1":"4","info2":"454","info3":"1"},{"queue_stats_id":"198183","datetime":"2016-06-16 15:39:51","qname":"5","qagent":"50","qevent":"10","info1":"4","info2":"1466062787.6382","info3":"3"},{"queue_stats_id":"198179","datetime":"2016-06-16 15:27:45","qname":"5","qagent":"50","qevent":"8","info1":"5","info2":"339","info3":"1"},{"queue_stats_id":"198178","datetime":"2016-06-16 15:22:06","qname":"5","qagent":"50","qevent":"10","info1":"5","info2":"1466061721.6337","info3":"4"},{"queue_stats_id":"198176","datetime":"2016-06-16 15:18:16","qname":"5","qagent":"53","qevent":"7","info1":"2","info2":"50","info3":"1"},{"queue_stats_id":"198175","datetime":"2016-06-16 15:17:26","qname":"5","qagent":"53","qevent":"10","info1":"2","info2":"1466061444.6325","info3":"1"},{"queue_stats_id":"198173","datetime":"2016-06-16 15:14:06","qname":"5","qagent":"50","qevent":"7","info1":"5","info2":"60","info3":"1"},{"queue_stats_id":"198172","datetime":"2016-06-16 15:13:06","qname":"5","qagent":"50","qevent":"10","info1":"5","info2":"1466061181.6318","info3":"4"},{"queue_stats_id":"198170","datetime":"2016-06-16 14:52:52","qname":"5","qagent":"53","qevent":"7","info1":"3","info2":"50","info3":"1"},{"queue_stats_id":"198169","datetime":"2016-06-16 14:52:02","qname":"5","qagent":"53","qevent":"10","info1":"3","info2":"1466059919.6275","info3":"3"},{"queue_stats_id":"198167","datetime":"2016-06-16 14:49:50","qname":"5","qagent":"28","qevent":"1","info1":"1","info2":"1","info3":"2"},{"queue_stats_id":"198165","datetime":"2016-06-16 14:25:44","qname":"5","qagent":"53","qevent":"7","info1":"47","info2":"162","info3":"1"},{"queue_stats_id":"198164","datetime":"2016-06-16 14:23:02","qname":"5","qagent":"53","qevent":"10","info1":"47","info2":"1466058176.6227","info3":"5"},{"queue_stats_id":"198163","datetime":"2016-06-16 14:22:51","qname":"5","qagent":"53","qevent":"0","info1":"15000","info2":"","info3":""},{"queue_stats_id":"198162","datetime":"2016-06-16 14:22:35","qname":"5","qagent":"50","qevent":"0","info1":"0","info2":"","info3":""},{"queue_stats_id":"198161","datetime":"2016-06-16 14:22:30","qname":"5","qagent":"53","qevent":"0","info1":"15000","info2":"","info3":""}]
嗨,我有這個PHP/JSON代碼.. 有人可以教我如何顯示此JSON使用TableLayout或到Android列表顯示?
對不起,即時通訊新的Android。 – Brewology
使用JSONOBJECT類來解析它。 –
好的,謝謝你,先生。 – Brewology