Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.0k views
in Technique[技术] by (71.8m points)

android - org.json.JSONException: Value [] of type org.json.JSONArray cannot be converted to JSONObject

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...