Php JsonException:用户ID没有值
我遇到了一个问题,我的json对象数组没有传递值。我知道它们在那里,但我无法让它们进入我的android应用程序中的变量Php JsonException:用户ID没有值,php,android,json,android-json,Php,Android,Json,Android Json,我遇到了一个问题,我的json对象数组没有传递值。我知道它们在那里,但我无法让它们进入我的android应用程序中的变量 The Java function to handle the JSONObject:/** * Function to get all userlogs **/ public JSONObject getUserLogs(String userid){ // userlogs JSONArray List<NameV
The Java function to handle the JSONObject:/**
* Function to get all userlogs
**/
public JSONObject getUserLogs(String userid){
// userlogs JSONArray
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("tag", getUserLogs_tag ));
params.add(new BasicNameValuePair("userid", userid));
JSONObject json = jsonParser.getJSONFromUrl(getAllUserLogs,params);
return json;
}
PHP:
else if ($tag == 'getUserLogs') {
$userid = $_POST['userid'];
//Special case (normally conntections handled in functions/config or connect)
$link = new mysqli($host, getDBuser(), getDBpassword(), getDBname());
/* check connection */
if (mysqli_connect_errno()) {
$response["error"] = 1;
$response["error_msg"] = mysqli_connect_error();
echo json_encode($response);
}
$query = "SELECT * FROM userlog WHERE userid = '$userid'";
$result = mysqli_query($link, $query);
$row_cnt = mysqli_num_rows($result);
//If results, then
if( $row_cnt > 0){
$response["userlogs"] = array();
while($row = mysqli_fetch_array($result, MYSQLI_BOTH)){
$userlog = array();
$userlog["userlogs"]["userid"] = $row["userid"];
$userlog["userlogs"]["medname"] = $row["medname"];
$userlog["userlogs"]["medtaken"] = $row["medtaken"];
$userlog["userlogs"]["tabsleft"] = $row["tabsleft"];
array_push($response["userlogs"], $userlog);
}
$response["success"] = 1;
echo json_encode($response);
mysqli_close($link);
}
else {
// userlogs not found
// echo json with error = 1
$response["error"] = 1;
$response["error_msg"] = "No Userlogs found";
echo json_encode($response);
}
}
else {
$response["error"] = 3;
$response["error_msg"] = "JSON ERROR";
echo json_encode($response);
}
}
有什么建议吗?你有什么建议吗
"userlogs": [ // jsonarray userlogs
{ // json object node
"userlogs": { // json object userlogs
然后
是的,很有道理。非常感谢:)
else if ($tag == 'getUserLogs') {
$userid = $_POST['userid'];
//Special case (normally conntections handled in functions/config or connect)
$link = new mysqli($host, getDBuser(), getDBpassword(), getDBname());
/* check connection */
if (mysqli_connect_errno()) {
$response["error"] = 1;
$response["error_msg"] = mysqli_connect_error();
echo json_encode($response);
}
$query = "SELECT * FROM userlog WHERE userid = '$userid'";
$result = mysqli_query($link, $query);
$row_cnt = mysqli_num_rows($result);
//If results, then
if( $row_cnt > 0){
$response["userlogs"] = array();
while($row = mysqli_fetch_array($result, MYSQLI_BOTH)){
$userlog = array();
$userlog["userlogs"]["userid"] = $row["userid"];
$userlog["userlogs"]["medname"] = $row["medname"];
$userlog["userlogs"]["medtaken"] = $row["medtaken"];
$userlog["userlogs"]["tabsleft"] = $row["tabsleft"];
array_push($response["userlogs"], $userlog);
}
$response["success"] = 1;
echo json_encode($response);
mysqli_close($link);
}
else {
// userlogs not found
// echo json with error = 1
$response["error"] = 1;
$response["error_msg"] = "No Userlogs found";
echo json_encode($response);
}
}
else {
$response["error"] = 3;
$response["error_msg"] = "JSON ERROR";
echo json_encode($response);
}
}
"userlogs": [ // jsonarray userlogs
{ // json object node
"userlogs": { // json object userlogs
userlogs = json.getJSONArray(KEY_USERLOGS); // fine
for (int i = 0; i < userlogs.length(); i++) {
JSONObject c = userlogs.getJSONObject(i);
JSONObject userlogsobject = c.getJSONObject("userlogs");
String userID = userlogsobject.getString(KEY_USERID);