Now I am getting this JSON from API:
{\"supplyPrice\": {
\"CAD\": 78,
\"CHF\": 54600.78,
\"USD\": 20735.52
}}
But
You need to iterate all keys of supplyPrice object, and create New JSONArray using that key value then assign new array to supplyPrice key
JSONObject changeSupplyPrice(JSONObject JSONObj){
try {
JSONObject supplyPrice =JSONObj.getJSONObject("supplyPrice");
JSONArray supplyPriceArray = new JSONArray();
Iterator> keys = supplyPrice.keys();
while( keys.hasNext() ) {
String key = (String)keys.next();
Log.e("JSON Array key",key);
supplyPriceArray.put(new JSONObject("{"+key+":"+supplyPrice.getString(key)+"}"));
}
JSONObj.put("supplyPrice", supplyPriceArray);
return JSONObj;
} catch (JSONException e) {
e.printStackTrace();
}
return null;
}
then call the function where you want
try {
JSONObject JSONObj = new JSONObject("{'taxes': [],'name': 'Laboriosam iusto eum','requiresShipping': false, 'taxable': true, 'sku': 'QBA84J18832', 'product': 12, 'supplyPrice': { 'CAD': 78, 'CHF': 54600.78, 'USD': 20735.52 }}");
JSONObj = changeSupplyPrice(JSONObj);
Log.e("Return JSON Object",JSONObj.toString());
} catch (JSONException e) {
e.printStackTrace();
}