I know how to get data from normal json data but recently I came across this new question where the json looks like
"product_1": {
"productId": "product_1",
"customerId": "customer_1",
"brandCode": "BRD0050",
"brandName": "ABC.ST.",
"productCode": 700251,
"productDesc": "ABC AB 50gm Sac",
"mrp": 15,
"expiry": 1608461977
},
"product_2": {
"productId": "product_2",
"customerId": "customer_1",
"brandCode": "BRD0050",
"brandName": "ABC.ST.",
"productCode": 700251,
"productDesc": "ABC AB 50gm Sac",
"mrp": 17,
"expiry": 1608462037
},
"product_3": {
"productId": "product_3",
"customerId": "customer_1",
"brandCode": "BRD0050",
"brandName": "ABC.ST.",
"productCode": 700251,
"productDesc": "ABC AB 50gm Sac",
"mrp": 17,
"expiry": 1608461978
}...
goes till product_150
so I looked for quite some time in google but not able to get any value this is what i have tried
try {
JSONObject obj = new JSONObject(loadJSONFromAsset());
// JSONArray m_jArry = obj.getJSONArray("product_" + j);
Iterator<String> keyIterator = obj.keys();
Log.e("Details",""+obj.keys().hasNext());
while(keyIterator.hasNext()) {
String productKey = keyIterator.next();
JSONObject jo_inside = obj.getJSONObject(productKey);
ArrayList<HashMap<String, String>> formList = new ArrayList<HashMap<String, String>>();
HashMap<String, String> m_li;
/* for (int i = 0; i < jo_inside.length(); i++) {
Log.e("Details",""+jo_inside.length());
Log.e("Details-->", jo_inside.getString("productId"));
String formula_value = jo_inside.getString("formule");
String url_value = jo_inside.getString("url");
//Add your values in your `ArrayList` as below:
m_li = new HashMap<String, String>();
m_li.put("formule", formula_value);
m_li.put("url", url_value);
formList.add(m_li);
}
*/
}
} catch (JSONException e) {
e.printStackTrace();
}
}
where I am getting data from the asset file. I have only tried to get data in Log any clue what I am doing wrong or what my approach should be? currently, I made a for loop till 150 and getting the data like that.
GSONor another libs for getting better result, take look at this: tutorialspoint.com/gson/index.htm