如何从JSON对象获取字符串数组

时间:2018-09-09 13:28:39

标签: android arrays json

我正在尝试从以下json对象中获取可用数字的列表

 void doJSONParser(String str)
    {
        try {

            JSONObject order = new JSONObject(str);
            JSONArray index = order.getJSONArray("webnautes");
            for(int i = 0; i < index.length(); i++)
            {
                JSONObject tt = index.getJSONObject(i);

                name += "name: " + tt.getString("name")+"\n";
                phone = new String[tt.getString("phone").length()];
                //phone += "phone: " + tt.getString("phone")+"\n";
            }

            Log.d("JSON DATA:", name);
            Log.d("JSON DATA:", phone.toString());

        }
        catch (JSONException e)
        {
            e.printStackTrace();
            Log.d("JSON ERROR", e.getLocalizedMessage());
        }

    }

1 个答案:

答案 0 :(得分:-1)

尝试一下

JSONArray phoneJson = tt.getJSONArray("phone");
String[] arr = new String[phoneJson.length()];
for(int i = 0; i < phoneJson.length(); i++)
    arr[i] = phoneJson.getString(i);
相关问题