0

i have a running app but i had a little problem with my sever,i have yet to solve my server problems and i'm encountering this problem with my log in the error comes from the authentication method.the error says jsonarray cannot be converted to jsonobject i've made a pastbin of my log and i was hoping someone can take a look at it and tell what my problem is.i think my problem is that i cant access my database but im not really sure if its the problem or my problem is my json.i cant hink of way to authenticate my username and password withour having problem like "at org.json.JSON.typeMismatch(JSON.java:111)" here is my paste bin http://pastebin.com/zgzbxcSV

1
  • what json string are you getting in response? Commented Jun 5, 2013 at 8:55

2 Answers 2

7

you get from the server a (maybe empty) json array and you are try to convert it in a JsonObject.

instead of

JSONObject obj = new JSONObject(string);

you should do

JSONArray obj = new JSONArray(string);
Sign up to request clarification or add additional context in comments.

6 Comments

the problem is with my log in activity.i was thinking it has something to do with my connection to the server?do you think i need to make another API because my code is working perfectly until i had a problem with my server.or i should reprogram my log in activity suggestion will be appreciated thank you
I will go with an AsyncTask, HttpUrlConnection and the android json library. It is a simply task to perform. Also check if something server side has changed
i tried doing it with JSONArray but then i get error in "pref_editor.putString("Name", result.getString("name"));" i need to make it an object right how can i make it in JSONArray?
What error did you get? Can you post the response of the server?
no error i put the logcat did you check it?i cant log in that is the server's response i think i cant get into the servers data base?coz i know my username and password is correct but i cant log in
|
1

You are trying to convert JsonObject to JsonArray so getting error.

You have to convert proper jsonObject to another object as per your requirement.

You can find useful demo with explanation.

If you find and trouble for parsing your json after researching this demo then let me know.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.