I need to get the id from this JSON.
{"previous_cursor_str":"0","next_cursor":0,"ids":[494942776,459450174,446965652,413869166,230653243,303016940,301473992,299765702],"previous_cursor":0,"next_cursor_str":"0"}
This json is the response from a url.
I tried the following, to get the id.
JSONObject json = JSONfunctions.getJSONfromURL("url");
JSONObject id = json.getJSONObject("ids");
Log.v("id....>>",id+"");
got the error.
02-17 22:34:10.995: W/System.err(418): org.json.JSONException: JSONObject["id"] not found.
您的JSON使用的是“ id”而不是“ id”。
Replace:
JSONObject id = json.getJSONObject("id");
with
JSONArray array = json.getJSONArray("ids");
Then loop through that...
You are getting "ids" JSONArrayObject.
JSONArray ids = json.getJSONArray("ids");
id = ids.getString(0);
First create Json object, if you are getting response as string use this:
JSONObject obj = new JSONObject(responseString);
Then get ids
JSONArray from it as :
JSONArray idArr = obj.getJSONArray("ids");
Now you have list of ids, to get first id use :
idArr.getLong(0)
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.