Моя среда Android, и я использую Xamarin для моего проекта. У меня есть проблема с моим подключением к серверу, для этого я использую JSon моя ошибка:Ошибка Json с xamarin
`Newtonsoft.Json.JsonReaderException: Error reading JObject from JsonReader. Current JsonReader item is not an object: String. Path '', line 1, position 2. at Newtonsoft.Json.Linq.JObject.Load`
мой код приложения сторона:
public async Task Login (string user_email, string user_password)
{
var content = new Dictionary<string, string> { {
"user_email",
user_email
},
{
"user_password",
user_password
}
};
String str = await ProcessPOST ("/api/login", content);
JObject data = JObject.Parse (str);
if (data ["success"] != null)
return (string)data ["success"];
throw new Exception ((string)data ["error"]);
}
и стороны сервера:
Итак, войдём
public function login() {
if ($this->method == "POST") {
if ($this->_data("user_email") && $this->_data("user_password")) {
$u_dao = new UserDAO();
$users = $u_dao->executeSelect("WHERE user_email = :user_email", array("user_email" => $this->_data("user_email")));
if (!isset($users[0]))
return $this->_response(array("error" => "User not found"), 403);
$user = $users[0];
if ($user && crypt($this->_data("user_password"), $user->user_password) == $user->user_password) {
$token = bin2hex(openssl_random_pseudo_bytes(16));
$user->user_token = $token;
$u_dao->update($user);
return $this->_response(array("success" => $token));
}
return $this->_response(array("error" => "Bad login"), 403);
}
return $this->_response(array("error" => "Missing data"), 500);
}
return $this->_response(array("error" => "Wrong method"), 405);
}
и код _response
protected function _response($data, $status = 200) {
header("HTTP/1.1 " . $status . " " . $this->_requestStatus($status));
return json_encode($data);
}
и теперь _requestStatus
private function _requestStatus($code) {
$status = array(
200 => 'OK',
403 => 'Forbidden',
404 => 'Not Found',
405 => 'Method Not Allowed',
500 => 'Internal Server Error',
);
return ($status[$code]) ? $status[$code] : $status[500];
}
и когда я пытаюсь соединить мой веб-сервис в Интернете, но я забыл, когда я сказал, есть ошибка, как «Missing Data» я не ошибка JObject но когда у меня есть успех, у меня есть ошибка.
так я показать все два ул одной ошибки:
"{\"error\":\"Missing data\"}"
и один из Succes:
"''{\"success\":\"db035db78a9f1e64d71c83bcbb45ffa5\"}"
я хочу сказал спасибо всем людям, которые помогают мне. И я сожалею о моем плохом английском, но я французский.
Я надеюсь быть ясным, но если у вас есть вопрос, вы можете спросить их.