please I am trying to get the URL from the JSON array thumbnail_images and it is inside another array which is medium_large, how can I get data from the second array. I have been able to get the URL from this JSON
"attachments": [
{
"id": 367,
"url": "http://street2view.com/wp-content/uploads/2017/01/mmm.png",
with this code:
JSONArray attachments = post.getJSONArray("attachments");
if (null != attachments && attachments.length() > 0) {
JSONObject attachment = attachments.getJSONObject(0);
if (attachment != null)
item.setAttachmentUrl(attachment.getString("url"));
}
so how can I get the data from an inner array like in this code how can I get the URL
"thumbnail_images": {
"medium_large": {
"url": "http://street2view.com/wp-content/uploads/2017/01/mmm.png",
"width": 749,
"height": 400
this is based on your example that does not have "thumbnail_images" as an array, but instead it's just a property
JSONObject images = post.getJSONObject("thumbnail_images");
JSONObject mediumLarge = images.getJSONObject("medium_large");
String url = mediumLarge.optString("url");
i've got it!
JSONObject images = post.getJSONObject("thumbnail_images");
JSONObject mediumLarge = images.getJSONObject("medium_large");
item.setAttachmentUrl(mediumLarge.optString("url"));
thanks to @classicalConditioning for the Hint.
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.