0

我有一个返回单个数字(即 360)的 php 文件。我怎样才能让那个数字出现在我的 android textview 中?我只熟悉如何使用如下所示的数组执行此操作:

{"success":1,"message":"Post Available!","posts":[{"name":"John Smith","id":"1"}, ...]}

但我怎么能用一个数字来做到这一点。

我制作了自己的 php,它制作了一个临时数组,如下所示:

{"success":1,"message":"Post Available!","posts":["records","383"]}

但我缺少大括号:[{"records","383"}]}

php是:

<?php

include('connect.php');

$counter = mysql_query("SELECT COUNT(*) AS id FROM users");
$nums = mysql_fetch_array($counter);
$count = $nums["id"];

$other["records"] = "records";
$other["counter"] = $count;


if ($nums) {
$response["success"] = 1;
$response["message"] = "Post Available!";
$response["posts"] = array();

for ($x=0; $x<=0; $x++){

//update our repsonse JSON data
array_push($response["posts"], $other["records"], $other["counter"]);
}

// echoing JSON response
echo json_encode($response);

} else {
$response["success"] = 0;
$response["message"] = "No Post Available!";
die(json_encode($response));
}

?>

如果有更好的方法来传递一个数字,那将很有帮助。谢谢。

4

1 回答 1

0

from what i googled TextView dosnt need json encoded data on input. it can be a string or integer. correct me if im wrong?

if im right this should work:

$counter = mysql_query("SELECT COUNT(*) AS id FROM users");
   $nums = mysql_fetch_array($counter);
  @mysql_close();

  die($nums["id"]);

于 2013-09-18T19:15:07.087 回答