当前位置:   article > 正文

list集合专为json数组_list转json数组

list转json数组

public static String toString(List<Map<String,Object>> list){
String str ="[";
if(list.size()>0) {
for (int i = 0; i < list.size(); i++) {
String mp = "";
if(i==0){
int num = 0;
Map<String, Object> map = list.get(i);
for (Object key : map.keySet()) {
num = num+1;
if(num==1){
mp = mp+"{\"" + key.toString() + "\" :\"" + map.get(key)+"\"";
}else {
mp = mp + ",\""+key.toString() + "\" :\"" + map.get(key)+"\"";
}
}
mp=mp+"}";
}else{
int num = 0;
Map<String, Object> map = list.get(i);
for (Object key : map.keySet()) {
num = num+1;
if(num==1){
mp = mp +",{\""+ key.toString() + "\" :\"" + map.get(key)+"\"";
}else {
mp = mp + ",\""+key.toString() + "\" :\"" + map.get(key)+"\"";
}
}
mp=mp+"}";
}
str=str+mp;
}
}

str=str+"]";
return str;
}

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/羊村懒王/article/detail/366828
推荐阅读
相关标签
  

闽ICP备14008679号