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
2 Answers
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);
6 Comments
Giant
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
Blackbelt
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
Giant
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?
Blackbelt
What error did you get? Can you post the response of the server?
Giant
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
|
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.