0

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);

1 Answer 1

2

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.