使用是fastjson
通过Arrays.asList()将String转为List<String>
如果传过来的是"['a','b']" 这种JSON类型,使用JSONUtil.parseArray(list, String.class);就转化为List<String>数据
比如
String s = "a" 转化为List<String>
1) List<String> list = Arrays.asList(a);
2)List<String> list = JSONUtil.parseArray(JSONUtil.toJSONString(Arrays.asList(a)) , String.class);
虽然有点奇奇怪怪的。。我为什么要把String转化为JSONString然后再转化List<String>
但是比如前台传过来的是一个JSON的String 类型,使用JSONUtil.parseArray还是挺有必要的。
比如
String s="[\"a\",\"b\",\"b\"]"这种格式
List<String> list= JSONUtil.parseArray(s, String.class);
这样就比较方便。