I was using API V3 (JAVA MailJet-client 4.0.5).
I try the new V3.1 (JAVA MailJet-client 4.1.1) with a very similar code (only required modifications).
I have this stack when I try top send a email :
JSONException:End of input at character 0 of
at org.json.JSONTokener.syntaxError(JSONTokener.java:484)
at org.json.JSONTokener.nextValue(JSONTokener.java:123)
at org.json.JSONObject.(JSONObject.java:156)
at org.json.JSONObject.(JSONObject.java:175)
at com.mailjet.client.MailjetClient.post(MailjetClient.java:218)
at org.zeroclick.common.email.MailjetMailSender.sendEmail(MailjetMailSender.java:156)
MailjetClient.java:218 try to convert the MailJet response
return new MailjetResponse(response.getStatus(), new JSONObject(json));
The json variable is an empty String, because the «response body» is empty.
This is the «header» of the response :
{Transfer-Encoding=[chunked], null=[HTTP/1.1 400 At least FromEmail or Sender must be provided], Date=[Thu, 29 Mar 2018 12:15:00 GMT], Content-Type=[text/html]}
The «null» parameter looks to be the «real» service response and is an error message.
This should be forwarded as an error to api-client developer ?
The guard Line just before (l216 and 217) could consider «empty body» AND «null» response.
To get more informations, #82 should be handled in this case (the «null» header» contain useful information to understand the «400» status an could be added to the «ErrorMessage» OR «ErrorInfo» field).
я использую AsyncTask для анализа JSON с сервера. но у меня возникла проблема, когда я запускаю свои приложения. в моем логарифме мой JSON выглядит нормально, но после этого появляется сообщение об ошибке android Error parsing data org.json.JSONException: End of input at character 0 of
. я уже пробовал некоторые предложения с форумов, но я все еще не нашел лучший способ решить эту проблему. вот мой код:
@Override
protected String doInBackground(String... arg0) {
// TODO Auto-generated method stub
List<NameValuePair> params = new ArrayList<NameValuePair>();
JSONObject json = jParser.makeHttpRequest(url_level_detaildatamerchant, "GET", params);
Log.d("Get List :", json.toString());
try {
int success = json.getInt(TAG_SUCCESS);
if (success == 1) {
data = json.getJSONArray(TAG_DATA);
for (int i=0; i<data.length(); i++) {
JSONObject c = data.getJSONObject(i);
Pk_Merchant_ID = c.getString(TAG_Pk_Merchant_ID);
Fk_Ms_DataLevel2_ID = c.getString(TAG_Fk_Ms_DataLevel2_ID);
Fk_Ms_City_ID = c.getString(TAG_Fk_Ms_City_ID);
Fk_Ms_Sales_ID_CreatedBy = c.getString(TAG_Fk_Ms_Sales_ID_CreatedBy);
Fk_Ms_Sales_ID_LastUpdateBy = c.getString(TAG_Fk_Ms_Sales_ID_LastUpdateBy);
CreatedDated = c.getString(TAG_CreatedDated);
LastUpdateDated = c.getString(TAG_LastUpdateDated);
Descriptions = c.getString(TAG_Descriptions);
Address = c.getString(TAG_Address);
Telpon = c.getString(TAG_Telpon);
Handphone = c.getString(TAG_Handphone);
BB_PIN = c.getString(TAG_BB_PIN);
email = c.getString(TAG_email);
Longitude = c.getString(TAG_Longitude);
Latitude = c.getString(TAG_Latitude);
Path_PhotoProfile = c.getString(TAG_Path_PhotoProfile);
Is_Deleted = c.getString(TAG_Is_Deleted);
HashMap<String, String> map = new HashMap<String, String>();
map.put(TAG_Pk_Merchant_ID, Pk_Merchant_ID);
map.put(TAG_Fk_Ms_DataLevel2_ID, Fk_Ms_DataLevel2_ID);
map.put(TAG_Fk_Ms_City_ID, Fk_Ms_City_ID);
map.put(TAG_Fk_Ms_Sales_ID_CreatedBy, Fk_Ms_Sales_ID_CreatedBy);
map.put(TAG_Fk_Ms_Sales_ID_LastUpdateBy, Fk_Ms_Sales_ID_LastUpdateBy);
map.put(TAG_CreatedDated, CreatedDated);
map.put(TAG_LastUpdateDated, LastUpdateDated);
map.put(TAG_Descriptions, Descriptions);
map.put(TAG_Address, Address);
map.put(TAG_Telpon, Telpon);
map.put(TAG_Handphone, Handphone);
map.put(TAG_BB_PIN, BB_PIN);
map.put(TAG_email, email);
map.put(TAG_Longitude, Longitude);
map.put(TAG_Latitude, Latitude);
map.put(TAG_Path_PhotoProfile, Path_PhotoProfile);
map.put(TAG_Is_Deleted, Is_Deleted);
listData.add(map);
}
}
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
Log.d("Error", e.toString());
}
return null;
}
и это мой php:
<?php
$response = array();
$dsn='sqlserver';
$username='street';
$password='keymaker';
$koneksi= odbc_connect($dsn,$username,$password);
if (isset($_POST['Fk_Ms_DataLevel2_ID'])) {
$Fk_Ms_DataLevel2_ID = $_POST['Fk_Ms_DataLevel2_ID'];
$query = "select * from Ms_Merchant where Fk_Ms_DataLevel2_ID = '$Fk_Ms_DataLevel2_ID' ";
$result = odbc_exec($koneksi, $query);
$response ["Ms_Merchant"] = array();
WHILE ($row = odbc_fetch_array($result)) {
$Ms_Merchant = array();
$Ms_Merchant["Pk_Merchant_ID"] = $row ["Pk_Merchant_ID"];
$Ms_Merchant["Fk_Ms_DataLevel2_ID"] = $row ["Fk_Ms_DataLevel2_ID"];
$Ms_Merchant["Fk_Ms_City_ID"] = $row ["Fk_Ms_City_ID"];
$Ms_Merchant["Fk_Ms_Sales_ID_CreatedBy"] = $row ["Fk_Ms_Sales_ID_CreatedBy"];
$Ms_Merchant["Fk_Ms_Sales_ID_LastUpdateBy"] = $row ["Fk_Ms_Sales_ID_LastUpdateBy"];
$Ms_Merchant["CreatedDated"] = $row ["CreatedDated"];
$Ms_Merchant["LastUpdateDated"] = $row ["LastUpdateDated"];
$Ms_Merchant["Descriptions"] = $row ["Descriptions"];
$Ms_Merchant["Address"] = $row ["Address"];
$Ms_Merchant["Telpon"] = $row ["Telpon"];
$Ms_Merchant["Handphone"] = $row ["Handphone"];
$Ms_Merchant["BB_PIN"] = $row ["BB_PIN"];
$Ms_Merchant["email"] = $row ["email"];
$Ms_Merchant["Longitude"] = $row ["Longitude"];
$Ms_Merchant["Latitude"] = $row ["Latitude"];
$Ms_Merchant["Path_PhotoProfile"] = $row ["Path_PhotoProfile"];
$Ms_Merchant["Is_Deleted"] = $row ["Is_Deleted"];
array_push($response["Ms_Merchant"], $Ms_Merchant);
}
$response["success"] = 1;
echo json_encode($response);
}
odbc_close($koneksi);
?>
Мне нужна твоя вся твоя помощь. заранее благодарю.
yesterday I came across the error mentioned below, so I started looking for similar questions on stackoverflow…but none of them seemed to help:(
My guess is that im getting no response from the server but I cant come up with an idea how to fix that. Im using like the same code in some other activities (of course with other functions) but al of them are working perfectly fine.
The only thing that changed is that I used Update table for the first time but I cant see how that would result in the following error.
I hope you can help me.
This is the error im getting:
org.json.JSONException: End of input at character 0 of
in the line of
JSONObject jsonResponse = new JSONObject(response);
This is the code in android studio:
Response.Listener<String> responseListener = new Response.Listener<String>() {
// this gets called on response
@Override
public void onResponse(String response) {
Log.d("Response:", "Register Response: " + response);
// check for boolean success from php
try {
JSONObject jsonResponse = new JSONObject(response);
Log.i("jsonResponse", jsonResponse.toString());
boolean success = jsonResponse.getBoolean("success");
// if true from php start LoginActivity
if (success){
Toast.makeText(RegisterActivity.this, jsonResponse.getString("error_msg"), Toast.LENGTH_LONG).show();
Intent intent = new Intent(RegisterActivity.this, LoginActivity.class);
RegisterActivity.this.startActivity(intent);
}
// if false build an AlertDialog
else {
Toast.makeText(RegisterActivity.this, jsonResponse.getString("error_msg"), Toast.LENGTH_LONG).show();
}
} catch (JSONException e) {
e.printStackTrace();
}
}
};
// call register request and transfer string username and password
RegisterRequest registerRequest = new RegisterRequest(email, password, matrikelnummer, firstName, surname, responseListener);
RequestQueue queue = Volley.newRequestQueue(RegisterActivity.this);
queue.add(registerRequest);
This is my PHP File:
if (isset($_POST["email"]) or isset($_POST["password"]) or isset($_POST["matrikelnummer"]) or isset($_POST["firstName"]) or isset($_POST["surname"])) {
$email = $_POST["email"];
$password = $_POST["password"];
$matrikelnummer = $_POST["matrikelnummer"];
$firstName = $_POST["firstName"];
$surname = $_POST["surname"];
$query = "SELECT * FROM Users WHERE Matrikelnummer ='$matrikelnummer'";
if ($result=mysqli_query($con,$query)) {
$anzahlrows = mysqli_num_rows($result);
if($anzahlrows == 1) {
$query = "UPDATE Users SET email = '$email' ,password = '$password',firstName = '$firstName', surname = '$surname' WHERE Matrikelnummer = '$matrikelnummer'";
if ($result=mysqli_query($con,$query)) {
$response["success"] = TRUE;
$response["error_msg"] = "Sie wurden erfolgreich angelegt!";
echo json_encode($response);
exit;
} else {
$response["success"] = FALSE;
$response["error_msg"] = "Fehler bei der INSERT SQL Abfrage";
echo json_encode($response);
exit;
}
}
else {
$response["success"] = FALSE;
$response["error_msg"] = "Die angegebene Matrikelnummer ist nicht verfügbar";
echo json_encode($response);
exit;
}
}
else {
$response["success"] = FALSE;
$response["error_msg"] = "Fehler bei der SQL Abfrage";
echo json_encode($response);
exit;
}
}
else {
$response["success"] = FALSE;
$response["error_msg"] = "Required parameters missing!";
echo json_encode($response);
exit;
}
The Log shows following:
D/Response:: Register Response:
W/System.err: org.json.JSONException: End of input at character 0 of
W/System.err: at org.json.JSONTokener.syntaxError(JSONTokener.java:449)
W/System.err: at org.json.JSONTokener.nextValue(JSONTokener.java:97)
W/System.err: at org.json.JSONObject.<init>(JSONObject.java:156)
.
.
.
-
Tags
Latest, PHP
Итак, я наконец получил ответ.
Самую неприятную проблему я обнаружил сам, а некоторые другие проблемы, которые вызвали проблемы, были обнаружены вами.
Так что моей самой большой ошибкой было то, что мне каким-то образом удалось удалить разрешение на доступ в Интернет.
Следующая проблема заключалась в том, что у меня не было .соединять();, поэтому спасибо @Levi Albuquerque
И спасибо @Barns за подсказки по улучшению.
Итак, вот рабочий код:
public class ReviewMetaDATA extends AsyncTask<String, Integer, String> {
private ProgressDialog progressDialog = new ProgressDialog(MainActivity.this);
HttpURLConnection urlConnection;
@Override
protected void onPreExecute() {
progressDialog.setMessage("Daten anfordern");
progressDialog.show();
progressDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
public void onCancel(DialogInterface arg0) {
ReviewMetaDATA.this.cancel(true);
}
});
}
@Override
protected String doInBackground(String... url) {
StringBuilder result = new StringBuilder();
try {
URL reviewmeta_url = new URL(url[0]);
urlConnection = (HttpURLConnection) reviewmeta_url.openConnection();
urlConnection.setRequestMethod("GET");
urlConnection.connect();
InputStream in = new BufferedInputStream(urlConnection.getInputStream());
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
String line;
while ((line = reader.readLine()) != null) {
result.append(line);
}
} catch (Exception e) {
Log.e("ERROR", "ERROR: " + e.toString());
} finally {
urlConnection.disconnect();
}
Log.d("Info", result.toString());
return result.toString();
}
@Override
protected void onProgressUpdate(Integer... values) {
}
@Override
protected void onPostExecute(String str) {
this.progressDialog.dismiss();
// When str is not empty then do that code
if (str != null && !str.isEmpty()) {
try {
JSONObject jresult = new JSONObject(str);
Log.d("REQUEST", jresult.getString("count"));
} catch (JSONException e) {
Log.e("JSON EXEPTION", "ERROR: " + e.toString());
}
}
// else log it
else{
Log.e("Request", "String was empty");
}
}
}
Спасибо за помощь.
И мне жаль, что я побеспокоил тебя этим.