志在指尖
用双手敲打未来

json格式string转list(json报文里包含list如何写)

json格式string转list

//后端调用接口
List<String>directives=newArrayList<>();
while(matcher.find()){
directives.add(matcher.group(1));
LOGGER.info(“处理标签:{}”,matcher.group(1));
}
JSONObjectjsonObject=newJSONObject();
Mapmap2=newHashMap();
//将List<String>转为JSON存储放入map中
map2.put(“marksList”,JSON.toJSONString(directives));
map2.put(“userId”,”SU000000000195″);
JSONObjectobj2=PostInterface.post(PostInterface.ServletName.placeholder,”queryPlaceHolderByMarks”,map2).getJSONObject(“SvcCont”);
List<Placeholder>pList=JSON.parseArray(obj2.getString(“placeHolderList”),Placeholder.class);

json

json报文里包含list如何写

下面就让小编来带大家学习“json数组怎样将字符串转list调集”吧!
1.json字符串
json字符串与一般的字符串没有任何特殊的当地,但是之所以称为json字符串是因为,这个字符串符合咱们之前介绍的语法规则。
2.json数组形式字符串转换为List>的8种办法
packagecom.zkn.newlearn.json;
importcom.alibaba.fastjson.JSON;importcom.alibaba.fastjson.JSONArray;importcom.alibaba.fastjson.JSONObject;
importjava.util.List;importjava.util.Map;
/**
*Createdbyzknon2016/8/22.
*/publicclassJsonToMapTest02{
publicstaticvoidmain(String[]args){
StringstrArr=”[{\”0\”:\”zhangsan\”,\”1\”:\”lisi\”,\”2\”:\”wangwu\”,\”3\”:\”maliu\”},”+
“{\”00\”:\”zhangsan\”,\”11\”:\”lisi\”,\”22\”:\”wangwu\”,\”33\”:\”maliu\”}]”;
//第一种办法List<Map<String,String>>listObjectFir=(List<Map<String,String>>)JSONArray.parse(strArr);
System.out.println(“使用JSONArray中的parse办法来解析json数组字符串”);
for(Map<String,String>mapList:listObjectFir){
for(Map.Entryentry:mapList.entrySet()){
System.out.println(entry.getKey()+””+entry.getValue());
}
}
//第二种办法List<Map<String,String>>listObjectSec=JSONArray.parseObject(strArr,List.class);
System.out.println(“使用JSONArray中的parseObject办法并指定回来类型来解析json数组字符串”);
for(Map<String,String>mapList:listObjectSec){
for(Map.Entryentry:mapList.entrySet()){
System.out.println(entry.getKey()+””+entry.getValue());
}
}
//第三种办法JSONArraylistObjectThir=JSONArray.parseArray(strArr);
System.out.println(“使用JSONArray中的parseArray办法来解析json数组字符串”);
for(ObjectmapList:listObjectThir){
for(Objectentry:((Map)mapList).entrySet()){
System.out.println(((Map.Entry)entry).getKey()+””+((Map.Entry)entry).getValue());
}
}
//第四种办法ListlistObjectFour=JSONArray.parseArray(strArr,Map.class);
System.out.println(“使用JSONArray中的parseArray办法并指定回来类型来解析json数组字符串”);
for(ObjectmapList:listObjectFour){
for(Objectentry:((Map)mapList).entrySet()){
System.out.println(((Map.Entry)entry).getKey()+””+((Map.Entry)entry).getValue());
}
}
//第五种办法JSONArraylistObjectFifth=JSONObject.parseArray(strArr);
System.out.println(“使用JSONObject中的parseArray办法来解析json数组字符串”);
for(ObjectmapList:listObjectFifth){
for(Objectentry:((Map)mapList).entrySet()){
System.out.println(((Map.Entry)entry).getKey()+””+((Map.Entry)entry).getValue());
}
}
//第六种办法ListlistObjectSix=JSONObject.parseArray(strArr,Map.class);
System.out.println(“使用JSONObject中的parseArray办法并指定回来类型来解析json数组字符串”);
for(ObjectmapList:listObjectSix){
for(Objectentry:((Map)mapList).entrySet()){
System.out.println(((Map.Entry)entry).getKey()+””+((Map.Entry)entry).getValue());
}
}
//第七种办法JSONArraylistObjectSeven=JSON.parseArray(strArr);
System.out.println(“使用JSON中的parseArray办法来解析json数组字符串”);
for(ObjectmapList:listObjectSeven){
for(Objectentry:((Map)mapList).entrySet()){
System.out.println(((Map.Entry)entry).getKey()+””+((Map.Entry)entry).getValue());
}
}
//第八种办法ListlistObjectEigh=JSONObject.parseArray(strArr,Map.class);
System.out.println(“使用JSON中的parseArray办法并指定回来类型来解析json数组字符串”);
for(ObjectmapList:listObjectEigh){
for(Objectentry:((Map)mapList).entrySet()){
System.out.println(((Map.Entry)entry).getKey()+””+((Map.Entry)entry).getValue());
}
}
}
}

未经允许不得转载:IT技术网站 » json格式string转list(json报文里包含list如何写)
分享到: 更多 (0)

评论 抢沙发

评论前必须登录!

 

志在指尖 用双手敲打未来

登录/注册IT技术大全

热门IT技术

C#基础入门   SQL server数据库   系统SEO学习教程   WordPress小技巧   WordPress插件   脚本与源码下载