//定义需要转换的类型(我这里需要的是Map,读者可以根据自己的情况将Map 换为相应的类)
List<Map<String,String>> listJson = null;
String jsonstr = property.getDatasource();//获取Json格式的字符串([{"label":"true","value":"1"},{"label":"false","value":"0"}] 此为我的JSO 字符串)JSONArray jarr = null;//定义JsonArray
if (!jsonstr.equals("")) {
jarr = JSONArray.fromObject(jsonstr);//将json字符串转换为JSONArray
listJson = JSONArray.toList(jarr,Map.class);//将JSONArray转换为list Map.class 可以转换为与读者自己定义相同的类
String[] options = new String[listJson.size()];
for(int i = 0;i<listJson.size();i++) //遍历list
{
options[i] = ""+listJson.get(i).get("label"); 取得遍历的值
}
}
1170

被折叠的 条评论
为什么被折叠?



