I want to get a json file from my server and display it in my android app.
For now, it is ok just showing in log console.
I am able to get the whole json file, something like:
[{"name":"john", "surname":"connor"}, {"name":"sarah", "surname":"connor"}]
But, in android if I try to use a string like this, it fails because []
If I try:
JSONObject json=new JSONObject(result); //result has the previous string
Log.i("TEST", json.toString());
I have to delete [ and ] to go ahead and nn log, I just have the first entrance of my json.
If I leave [ and ], it just do nothing. Stop before the first line.
The complete example code is here .
Replace this
JSONObject json=new JSONObject(result); //result has the previous string
Log.i("TEST", json.toString());
With
JSONArray json=new JSONArray(result); //result has the previous string
Log.i("TEST", json.toString());
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.