Reputation: 53
"response": {
"code": "0",
"comment": "",
"log_id": "51c55b29-e1e7-4855-9fd8-d920eff82fbe"},
"styles": {
"style": [{
"style_id": "3745150",
"style_name": "Westy",
"style_number": "WEST01M1",
"style_identifier": "WEST01M1||",
"style_description": "",
"made_to_order": "True",
"division": "MEN'S SHOES",
"division_code": "M1",
"style_country_origin": "",
"measurements": "",
"fabrication": "",
"fabrication_code": "",
"silhouette": "",
"silhouette_code": "",
"source_of_materials": "",
"heel_height": "",
"contains_fur": "",
"best_seller": "False",
"minimum": "12",
"categories": [
{
"category_parent": "Men's",
"subcategories": [{
"subcategory_parent": "Shoes",
"subcategory": [
{
"subcategory_id": "840",
"subcategory_label": "Casual"
}
]}
]}
],
"prices": [
{
"price_label": "",
"price_currency": "USD",
"price_wholesale": 30.00,
"price_retail": 75.00,
"price_currency_retail": "USD"
}
],
"colors": [{
"color_name": "Black",
"color_code": "1",
"color_image": "",
"color_swatch": "/img/uploads/accounts/280561/images/WEST01M1 (1).jpg",
"minimum": "0"
}]
,
"images": [
"/img/uploads/accounts/280561/images/WEST01M1.jpg"
]
}, {
"style_id": "3745126",
"style_name": "Clarity",
"style_number": "CLAR01M1",
"style_identifier": "CLAR01M1||",
"style_description": "",
"made_to_order": "True",
"division": "MEN'S SHOES",
"division_code": "M1",
"style_country_origin": "",
"measurements": "",
"fabrication": "",
"fabrication_code": "",
"silhouette": "",
"silhouette_code": "",
"source_of_materials": "",
"heel_height": "",
"contains_fur": "",
"best_seller": "False",
"minimum": "12",
"categories": [
{
"category_parent": "Men's",
"subcategories": [{
"subcategory_parent": "Shoes",
"subcategory": [
{
"subcategory_id": "840",
"subcategory_label": "Casual"
}
]}
]}
],
"prices": [
{
"price_label": "",
"price_currency": "USD",
"price_wholesale": 57.50,
"price_retail": 125.00,
"price_currency_retail": "USD"
}
],
"upcs": [
{
"sku_color_code": "1",
"sku_size": "7",
"upc": "888509010764",
"inventory_available": "0"
},
{
"sku_color_code": "1",
"sku_size": "7.5",
"upc": "888509010771",
"inventory_available": "0"
},
{
"sku_color_code": "1",
"sku_size": "8",
"upc": "888509010788",
"inventory_available": "0"
},
}]
I have above Json object in a string variable.
Can somebody tell me how to access the "price_currency" in prices?
JSONObject json = new JSONObject(output);
String sc = json.get("styles").toString();
I got styles using above method,
after than i got style using below code. Style is inside the styles.
JSONObject json1 = new JSONObject(sc);
String sc1 = json1.get("style").toString();
Now i want to get "price_currency" in prices? how do i do that?
Upvotes: 2
Views: 14804
Reputation: 18235
Your prices is inside an array
. You have to access the element inside array by index first
JSONObject outputJson = new JSONObject(output);
JSONObject style = outputJson.getJsonObject("styles").getJsonArray("style").getJsonObject(0);
JSONObject price = style.getJsonArray("prices").getJsonObject(0);
String currency = price.getString("price_currency");
Edit
JSONArray
implements List<JSONObject>
so you can do:
for (JSONObject price : style.getJsonArray("prices")) {
String currency = price.getString("price_currency");
}
Upvotes: 3