Reputation: 67
after i import the project and fix some problem i got the json error like the title i mention, can you help me please. In the IDE nothing with error sign (red sign)
if you need anything else just ask below
Here is my code
@Override
protected void onPostExecute(String Result) {
dialog.dismiss();
if (Result != null) {
parseJson(Result); // here problem
} else {
// intent_depan();
Toast.makeText(LoginActivity.ctx,
"Login Failed, Connection Error", Toast.LENGTH_SHORT)
.show();
}
}
// Android monitor show the problem maybe here
public void parseJson(String s) {
try {
JSONObject jobj = new JSONObject();
String stat = jobj.getString("stat");
// Log.i("json result", "string result " + s1);
if (stat.equals("failed")) {
String msg = jobj.getString("msg");
Toast.makeText(LoginActivity.ctx, msg, Toast.LENGTH_SHORT)
.show();
} else {
userName = jobj.getString("name");
// Toast.makeText(LoginActivity.ctx, userName,
// Toast.LENGTH_SHORT).show();
saveLoginState();
goToMainActivity();
}
/*
* if (s1 == "success") { intent_depan(); } else {
* intent_depan(); }
*/
} catch (JSONException e) {
e.printStackTrace();
Toast.makeText(LoginActivity.ctx, e.getMessage(),
Toast.LENGTH_SHORT).show();
}
}
Upvotes: 0
Views: 1051
Reputation: 78825
The server's response cannot cannot be parsed as JSON because the server returns an error message (in HTML) instead of JSON data.
It's a HTTP 404 Not found error, indicating that the URL was probably invalid.
It would also be good practice to check if the HTTP request was successful at all. If it wasn't, don't even try to parse the response as JSON.
Upvotes: 0
Reputation: 131
creat a json object from result like this and before parsing also check the result string is a valid json string or not.
JSONObject jobj = new JSONObject(s);
Upvotes: 1