0

I am A beginner at the android studio. I want to parse a JSON object and I want to display it like this.

String mNames[] = {"name1", "name2", "name3"};

How Can I do this.

nas
  • 29
  • 5

1 Answers1

0

You can use JSONObject and JSONArray as displayed in the following example:

{'profiles': [{'name':'john', 'age': 44}, {'name':'Alex','age':11}]}

JSONObject myjson = new JSONObject(the_json);
JSONArray the_json_array = myjson.getJSONArray("profiles");

int size = the_json_array.length();
ArrayList<JSONObject> arrays = new ArrayList<JSONObject>();
for (int i = 0; i < size; i++) {
    JSONObject another_json_object = the_json_array.getJSONObject(i);
        //Blah blah blah...
        arrays.add(another_json_object);
}

//Finally
JSONObject[] jsons = new JSONObject[arrays.size()];
String[] blah = arrays.toArray(jsons);

(Taken from How to parse a JSON and turn its values into an Array?)

Also, just for your information, this process has nothing to do with Android Studio itself, rather with Java and JSON ^^

ProgFroz
  • 165
  • 3
  • 16