Skip to content Skip to sidebar Skip to footer

Json Parsing Without Array Name Or Node In Android

I have a JSOn array without array name and I'm confused how to parse it and how to make JSONObject or JSONArray. If possible then please describe it. My JSON Array list is: [{ name

Solution 1:

Try this:

try {
      JSONArray jsonArray = newJSONArray(response);
      for (int i = 0; i <jsonArray.length() ; i++) {
     JSONObject jsonObject = (JSONObject) jsonArray.get(i);  
     textView.setText(jsonObject.getString("name"));   
     }    
    } catch (JSONException e) {
      e.printStackTrace();
   }

Solution 2:

You can pass the response string to the JSONArray constructor directly and then parse the array using a loop

JSONArray jsonArray = newJSONArray(response);

Tip: I would search how to use other json libraries like Gson or Jackson as the Android built-in parser is not good.

Post a Comment for "Json Parsing Without Array Name Or Node In Android"