I read various topics and found similar problems, but could not find a solution to my specific problem.
JSONObject orr = (JSONObject)orderRows.get("orderRows"); System.out.println("data in orr = " + orr + "orr type = " + orr.getClass());
Return:
data in orr = {"470": [{"locationId": 2, "quantity": 1, "ProductID": 1007}], "471": [{"locationId": 2, "quantity": 1, " ProductID ": 1008}]} Orra type = class org.json.simple.JSONObject
I am trying to get this data into an array / list / everything where I can use keys 470,471 to retrieve data.
Any suggestions or pointers really appreciate many thanks ...
To clarify:
JSONObject orr = (JSONObject)orderRows.get("orderRows"); JSONArray orderOne = (JSONArray)orr.get("471"); System.out.println(orderOne); System.out.println(orderOne.get(0)); JSONObject orderOneKey = (JSONObject)orderOne.get(0); System.out.println(orderOneKey.get("productId"));
This is what I need, but I cannot do orr.get ("471"), because I do not know what the number is.
EDIT: Apparently, I cannot answer my question within 8 hours:
Thanks to the help of a friend and some vocalists, I found a solution, I am sure that this is not the most eloquent, but this is exactly what I wanted:
for(Object key: orr.keySet()) { JSONArray orderOne = (JSONArray)orr.get(key); JSONObject ordervalue = (JSONObject)orderOne.get(0); System.out.println(ordervalue.get("productId")); }
Thanks for the help and suggestions guys.