java接受字符串,先将JSON字符串变为JSON对象,然后再或者JSON对象中的各个值,可以是字符串,也可能是数组。
String str1="{\"name\":\"lss\"}";
JSONObject jsonObject=JSONObject.parseObject(str); // 将JSON字符串转为JSON对象
// Object list = jsonObject.get("unitList");
System.out.println(jsonObject);
JSONArray ja = jsonObject.getJSONArray("unitList"); // JSON对象获取其中的数组
List<String> list = new ArrayList<String>();
for (int i = 0; i < ja.size(); i++) {
System.out.println(ja.get(i));
list.add((String) ja.get(i));
}