如何更改listView中json解析项的顺序?

时间:2011-11-03 21:53:28

标签: php android json

我正在使用来自我的服务器数据库的JSON解析数据,但我列表中的演示文稿是从最后一个id到第一个id。我希望将0从0到任何id都有,例如20.这可能吗?

这是我的php课程:

<?
header('content-type: text/html; charset=utf-8');
$link1 = mysql_pconnect("host", "username", "pass") or die("Could not connect");
        mysql_select_db("dbname") or die("Could not select database");

$query= mysql_query("SET NAMES 'utf8'");
$rs = mysql_query("select * from vathmoi ORDER BY  vathmoi.id DESC");
while($obj = mysql_fetch_object($rs)) {
    $arr[] = $obj;
}
  function replace_unicode_escape_sequence($match) {
    return mb_convert_encoding(pack('H*', $match[1]), 'UTF-8', 'UTF-16BE');
}
$str = preg_replace_callback('/\\\\u([0-9a-f]{4})/i', 'replace_unicode_escape_sequence', json_encode($arr));
echo '{"as_of":"Today!","trends":'.$str.'}';

?>

1 个答案:

答案 0 :(得分:0)

ORDER BY vathmoi.id DESC更改为ORDER BY vathmoi.id ASC

另外,请研究使用PHP的json_encode函数输出您的JSON字符串。

编辑:没关系,我没有看到你在回调中使用了json_encode。不知道你为什么需要这个回调... json_encode通常可以很好地转义你的数据,以便它是有效的JSON,但是我再也不知道你从数据库中提取了什么数据。

相关问题