Skip to content

java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 1 column 1 path $ #10

@mohamedmidoz

Description

@mohamedmidoz

when I import my DB From a server to a localServer on my PC using XAMPP then I try to fetch data from DB using JSON Api and Retrofit I found that error

java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 1 column 1 path $
My Api.php that is in C:\xampp\htdocs\

<?php

include 'DB.php';
$db = DB::getInstance();
header("Content-Type: application/json;charset=utf-8");

function UserLoginMethod($username , $password , $lat, $long){
    global $db;
    $sql = "SELECT * FROM users WHERE user_email = ? AND  user_password = ?
             LIMIT 1";
    $user_info = $db->query($sql, [$username, $password]);


    CheckIsEmpty($user_info);
    //echo $db->getSQL();
    echo PrintJSON($user_info[0]);

}

switch (@$_GET['function']) {
    case "Login":
        UserLoginMethod(@$_GET['user_email'], @$_GET['user_password'], $_GET['user_location_latitude'], $_GET['user_location_longitude']);
        break;


}



function CheckIsEmpty($query) {
    if (is_null($query)||empty($query)){
        die (json_encode(array('error' => 'no items funded.'),JSON_FORCE_OBJECT));
    }
}
function PrintJSON($q){
    $j = json_encode($q);
    if (count($j) > 0 && !is_null($q) )
        return $j;
    else
        die (json_encode(array('error' => 'no items funded.'),JSON_FORCE_OBJECT));
}


function CreateDieError($body){
    die (json_encode(array("error" => $body),JSON_FORCE_OBJECT));
}

?>

the current development environment in DB.php that is in C:\xampp\htdocs\

$db_config = [
//current development environment
"env" => "development",
//Localhost
"development" => [
"host" => "127.0.0.1",
"database" => "egydcom_family",
"username" => "root",
"password" => ""
],
//Server
"production" => [
"host" => "127.0.0.1",
"database" => "egydcom_family",
"username" => "root",
"password" => ""
]
];

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions