java: how to convert this string to ArrayList?

后端 未结 4 1636
说谎
说谎 2021-01-28 01:47
String text = \'[[\"item1\",\"item2\",\"item3\"], [\"some\", \"item\"], [\"far\", \"out\", \"string\"]]\';

I would like to iterate over each individual

4条回答
  •  难免孤独
    2021-01-28 02:31

    Since you are using a string that looks like JSON, I would just use a JSON parser. One of the simplest to uses is gson. Here is an example using gson:

    String text = '[["item1","item2","item3"], ["some", "item"], ["far", "out", "string"]]';
    GSON gson = new GSON();
    ArrayList> list = gson.fromJson(text, new TypeToken>>() {}.getType());
    

    Here is the gson site: http://code.google.com/p/google-gson/

提交回复
热议问题