0
String mensao = "[\"brega_falcao\",\"SamiPietikainen\",\"TecRahul\",\"gpantuza\",\"mkyong\",\"mkyong\",\"YouTube\"]";
Mensao is the Jsonarray I want to convert.
I tried that but it didn’t work:
//Retiro o '[' do inicio e do fim ']' do array json
String modificada = mensao.substring(1, mensao.length() - 1);
List<String> lista = Arrays.asList(modificada);
for (int i = 0; i < lista.size(); i++) {
System.out.println(i + " " + lista.get(i));
}
The problem is that it prints a big string and doesn’t create an array of strings...(that’s what I told the code to do, but that’s not what we want...)
Exit
0 "brega_falcao","SamiPietikainen","TecRahul","gpantuza","mkyong","mkyong","YouTube"
As long as that’s what you want:
0 brega_falcao
1 SamiPietikainen
2 TecRahul
3 gpantuza
4 mkyong
5 mkyong
6 YouTube
Thanks, but as I can return a String Array instead of printing, you can add this function to your reply?
– Pena Pintada
@Painted penada When you say "array", you actually say a
array
or a list (as in the example of your question)?– Felipe Marinho
String[] string = new String[size];
– Pena Pintada
@Penapintada Added in the answer.
– Felipe Marinho