-1

I got JSON file like this:

{
"issues": [
        {
           "no1": 5509,
           "date": 1451520000
        },
        {
           "no1": 6713,
           "date": 1451433600
        }],
"no2": [
    220380,
    163950,
    213330,
    215250,
    174300]
}

I need to create a map issues where the no1 value will be key of the map and date value will be a value of the map. I've got already method which transfers JSON to map from file, and I know how to get the issues which will be: mapFromJson.get("issues"); what I get is:

issues=[{ no1: 5509.0, date: 1.45152E9}, {no1: 6713.0, date: 1.4514336E9}]

How to convert this to map?

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
shurrok
  • 795
  • 2
  • 13
  • 43

1 Answers1

1

You can convert to JSON using JSON Library (you must to attach JAR file in your project). Also, I found a good answer for convert JSON to Map in this link. I recommended to use these functions.

Example:

JSONObject json = new JSONObject(<your_json_string>);
ArrayList issues =  (ArrayList) jsonToMap(json).get("issues");

Each element in the ArrayList issues, it's already HashMap. For example, if you want to get date of no1, you could access of this way:

((HashMap)issues.get(0)).get("date")
VIX
  • 605
  • 4
  • 15