-4

How to fix this error in my logcat...

org.json.JSONException: Value of type java.lang.String cannot be converted to JSONObject

enter image description here

4
  • show me your string Commented Mar 10, 2017 at 10:09
  • 2
    Possible duplicate of Java String to JSON conversion Commented Mar 10, 2017 at 10:11
  • Your data return ... HTML format, it 's not JSON format. You must be sure your data reuturn JSON. Maybe your request is not correct. Commented Mar 10, 2017 at 10:22
  • I fix my first error and now my error is JSONException: End of input at character 0 of Commented Mar 10, 2017 at 13:54

2 Answers 2

2

your string which is logged in the clip is in HTML format, not JSON.

https://developer.android.com/reference/org/json/JSONObject.html

JSONObject jobj = new JSONObject();
try {
     jobj = new JSONObject(string);
} catch (JSONException e) {
     //e.printStackTrace();
}

will give you a json object if your input is in correct json format

Sign up to request clarification or add additional context in comments.

2 Comments

I fix my first error and now my error is JSONException: End of input at character 0.
that usually means empty/null string was parsed, show the string you're passing now
1
try {

    JSONObject jsonObject = new JSONObject(YOUR_STRING);
} 
catch (JSONException e) {
   e.printStackTrace();
}

1 Comment

I fix my first error and now my error is JSONException: End of input at character 0.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.