Hi every one I followed this one to parse JSON from a URL but at the time of parsing I strucked at one place.. as
Now I am not getting images please Help. IMAGES, DETAILS ,OFFERS those are not Getting .. They are in jsonarray(jsonobject(jsonarray(jsonobject))) please help
I have a image inside a array like below
{
"returnCode": "success",
"Data": {
"results": [
{
"moredetails": [
{
"newoffers": [
],
"recentoffers_count": 0,
"sku": "30072246"
},
{
"newoffers": [
{
"availability": "Available",
"currency": "USD"
}
]
},
{
"newoffers": [
{
"availability": "Available",
"currency": "USD"
}
],
"offers_count": 1,
"name": "google.com"
}
],
..."features": {
..
},
"length": "20",
"geo": [
"usa"
],
.."images": [
"http://google.com.one.jpg"
],
..
}
],
...
}
}
Now I want how to parse some of the contents like Images, newoffers which are inside jsonarray(jsonarray) i mean they are like [{ [{ and [{[ json array inside json array I tried but I am getting error at
JSONArray json_results = json_results.getJSONArray("images");
This is my code..
try {
JSONObject json_data = JSONfunctions.getJSONfromURL(url);
JSONObject json_SemanticS3ProductData = json_data.getJSONObject("Data");
JSONArray json_results = json_SemanticS3ProductData.getJSONArray("results");
for (int i = 0; i < json_SemanticS3ProductData.length(); i++) {
HashMap<String, String> map = new HashMap<String, String>();
JSONObject c = json_results.getJSONObject(i);
map.put("model", c.optString("model"));
JSONObject f = c.getJSONObject("features");
map.put("Rear-facing Camera", f.optString("Rear-facing Camera"));
JSONArray json_results_images = json_results.getJSONArray("images");
arraylist.add(map);
JSONArray json_sitedetails =json_results.getJSONArray("details");
for (int j = 0; j < json_sitedetails.length(); j++) {
HashMap<String, String> map1 = new HashMap<String, String>();
JSONObject sd = json_sitedetails.getJSONObject(j);
JSONArray json_latestoffers = json_sitedetails.getJSONArray("offers");
for (int k = 0; k < json_sitedetails.length(); k++) {
HashMap<String, String> map2 = new HashMap<String, String>();
JSONObject e = json_latestoffers.getJSONObject(k);
map1.put("currency", e.optString("currency"));
arraylist.add(map1);
}
}
}
}
remaning all are fine. but I am unable to parse images,details,and offers.. please help. Those three are inside the jsonarray(jsonObject (Jsonarray(jsonobject))) this is the thing.. Please help..
I created an incomplete snippet. With your given example it can access at least up to the first new_offers, sku, etc. This is incomplete though as it will fail if a field does not exist. Anyway the purpose of the snippet is just to show you how to retrieve the value from a nested JSONObject and JSONArray