Android JSON to String Convert getStringArray(JSONArray jsonArray)

Here you can find the source of getStringArray(JSONArray jsonArray)

Description

A helper method to convert one dimensional JSONArrays to StringArrays.

Parameter

Parameter Description
jsonArray the JSONArray to convert

Exception

Parameter Description
JSONException exception during JSON parsing

Return

stringArray the converted StringArray

Declaration

public static String[] getStringArray(JSONArray jsonArray)
        throws JSONException 

Method Source Code

//package com.java2s;

import org.json.JSONArray;
import org.json.JSONException;

public class Main {
    /**/*from   w  w w  . j av a  2s  .c  o m*/
     * A helper method to convert one dimensional JSONArrays to StringArrays.
     * @param jsonArray the JSONArray to convert
     * @return stringArray the converted StringArray
     * @throws JSONException exception during JSON parsing
     */
    public static String[] getStringArray(JSONArray jsonArray)
            throws JSONException {
        String[] stringArray = new String[jsonArray.length()];
        for (int i = 0; i < jsonArray.length(); i++) {
            stringArray[i] = jsonArray.getString(i);
        }
        return stringArray;
    }
}

Related

  1. getJsonErrorMsg(JSONObject errorResponse)
  2. pakJson(String json, String... jsons)