android how to convert json array to string array

后端 未结 5 1681
时光取名叫无心
时光取名叫无心 2020-12-09 21:22

I have an app where I fetch data from server(json) in the form of array & by using the index i used in my app, like below.

JSONObject topobj = new JSONOb         


        
5条回答
  •  臣服心动
    2020-12-09 21:44

    I just did this yesterday! If you're willing to use a 3rd party library then you can use Google GSON, with the additional benefit of having more concise code.

    String json = jsonArray.toString();
    Type collectionType = new TypeToken>(){}.getType();
    Collection strings = gson.fromJson(json, collectionType);
    
    for (String element : strings)
    {
        Log.d("TAG", "I'm doing stuff with: " + element);
    }
    

    You can find more examples in the user guide.

提交回复
热议问题