Random values being printed when I print the keyset after reading a JSON file in java

Viewed 30

I have a JSON file which follows the format like this -

[
    {"2022-09-03": {
        "AUD": {
            "SGD": 0.96,
            "JPY": 95.29,
            "GBP": 0.59,
            "USD": 0.68,
            "CNY": 4.69
        },
        "SGD": {
            "AUD": 1.042,
            "JPY": 100.09,
            "GBP": 0.62,
            "USD": 0.71,
            "CNY": 4.92
        }
  }}
]

And I'm trying to extract the keys that is present that is all the dates which are of the type string. However, when I try to read the values -

public void readJSON(Update obj, String currency_1, String currency_2, String date_1, String date_2) {
  for (int i = 0; i < obj.getJsonAll().length(); i++) {
    extractedDates.add(obj.getJsonAll().getJSONObject(i).keySet());
  }
  System.out.println(extractedDates);
  
  for (Set s: extractedDates) {
    System.out.println(s);
  }
}

Output:

[[2022-09-03], [2022-09-04], [2022-09-05], [2022-09-06]]
[2022-09-03]022-09-04
[2022-09-04]
[2022-09-05]
[2022-09-06]
The summary of AUD SGD between 2022-09-03 and 2022-09-04 is:
Would you like to perform more operations? (YES/NO):

Some random values of other dates get concatenated to it. I'm not sure why that's happening, it's not like I have written faulty code. Could I please get some help as to why this is happening? Thanks

0 Answers
Related