0

Can someone please help in parsing the JSON object in below format? The counter is dynamic and can be less, can be more. I want to get formattedBasePrice for all instances and store it in an array. What's the easiest way?

Thanks!

{
    "sales":
    {
        "0":
        {
            "formattedBasePrice": "$9.99",
            "formattedSalePrice": "$4.99",
            "formattedPlusPrice": "$4.99"
        },
        "1":
        {
            "formattedBasePrice": "$29.99",
            "formattedSalePrice": "$18.89",
            "formattedPlusPrice": "$7.79"
        }
    }
}
Forged
  • 171
  • 10
  • Check out https://stackoverflow.com/questions/2591098/how-to-parse-json-in-java – Kryštof Vosyka Jun 08 '21 at 08:31
  • 1
    This JSON in not valid. – icalvete Jun 08 '21 at 16:02
  • What languaje are you using? java? – icalvete Jun 08 '21 at 16:05
  • Thanks for all the help, was able to solve my problem using org.json.JSONObject. Yes, I'm using java. Had to do something like this: `JSONObject countobj = obj.getJSONObject("sales"); for(int j=0;j< (countobj.length()); j++) { String price = obj.getJSONObject("sales").getJSONObject(Integer.toString(j)).getString("formattedBasePrice"); p.add(price); }` – Forged Jun 11 '21 at 07:14

0 Answers0