0Shift
0Shift

Reputation: 3

Parsing a JSON Array into a Java array returns the last element as the second index

So I'm working with a local JSON file, and when I try to parse it into a Java data structure everything goes fine except as the title suggests, the last element of the JSON array is returned as the second element of the Java array

        "text": [
            {
                "0": "text"
            }, {
                "3": "text"
            }, {
                "5": "text:"
            }, {
                "6": "text:"
            }, {
                "7": "text:"
            }, {
                "8": "text"
            }, {
                "9": "text:"
            }, {
                "9": "text"
            }, {
                "10": "text:"
            }, {
                "11": ""
            }
        ]
   for(int j = 0; j < arr.length(); j++) {
                    String index = content.getJSONObject(j).names().get(0).toString();
                    String ToCVal = content.getJSONObject(j).getString(index);
                    temp_hashmap.put(index, ToCVal);

Upvotes: 0

Views: 71

Answers (1)

Granit Berisha
Granit Berisha

Reputation: 86

Thats not a problem with the JsonObject, its a problem with HashMap you have to use LinkedHashMap to save the order

Upvotes: 2

Related Questions