0

I'm tried to parse some json array (with string and two-dimensional array) into objects array, but the solutions I found do not work (or I was looking bad). Please, help me with the code to get an array of objects.

I found working method for Java (I tried it in Eclipse) this, but I want it for Android (in Android Studio)

My json file:

[
    {
        "someString": "First string",
        "someTwoDimArray":
        [
            ["First_firstElement", "First_secondElement"],
            [true, false]
        ]
    },

    {
        "someString": "Second string",
        "someTwoDimArray":
        [
            ["Second_firstElement", "Second_secondElement"],
            [true, true]
        ]
    }
]

I have java class:

public class someClass {
    String someString;
    Object[][] someTwoDimArray;
}

What I need: (To process the data in the code later)

someClass[] someClasses = /* ??? */
2

1 Answer 1

0

Try something like this:

            JSONArray jsonarray = new JSONArray(jsonStr);

            int L = yourArrayWithJSON.length();

            first = new String[L];
            second = new String[L];
            third = new String[L];

            for (int i = 0; i < L; i++) {
                JSONObject point = vpn.getJSONObject(i);
                first[i] = point.getString("first");
                second[i] = point.getString("second");
                third[i] = point.getString("third");  
                String url = jsonobject.getString("url"); 
            }

Ask, if you have any questions

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.