Welcome to OGeek Q&A 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 Reply

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...