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 = /* ??? */
  • Possible duplicate of [How to parse JSON Array (Not Json Object) in Android](https://stackoverflow.com/questions/18977144/how-to-parse-json-array-not-json-object-in-android) – A.Najafi Dec 24 '18 at 21:37
  • i strongly recommend using the gson library for doing that – DennisVA Dec 24 '18 at 21:41

1 Answers1

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

Valentin
  • 400
  • 2
  • 11