分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 教程案例

json数据的转换

发布时间:2023-09-06 01:46责任编辑:熊小新关键词:jsjson
一://json数组类型字符串取值var jsonStr = ‘[{"id":"01","open":false,"pId":"0","name":"A部门"},{"id":"01","open":false,"pId":"0","name":"A部门"},{"id":"011","open":false,"pId":"01","name":"A部门"},{"id":"03","open":false,"pId":"0","name":"A部门"},{"id":"04","open":false,"pId":"0","name":"A部门"}, {"id":"05","open":false,"pId":"0","name":"A部门"}, {"id":"06","open":false,"pId":"0","name":"A部门"}]‘;var jsonObj = ?JSON.parse(jsonStr);//转换为json对象for(var i=0;i<jsonObj.length;i++){ ???????alert(jsonObj[i].id); ?//取json中的值}console.log(jsonObj)var jsonStr1 = JSON.stringify(jsonObj)console.log(jsonStr1+"jsonStr1")

二:

public static void main(String[] args) throws Exception {
List list=new ArrayList<>() ;
ArrayList<Object> alist=new ArrayList<>();
  Map<Object, List> map=new HashMap<Object, List>();
list.add("ss");
list.add("dd");
alist.add("hh");
alist.add("yy");
map.put("a", list);
map.put("b", alist);
String ss=JSON.toJSONString(map);

JSONObject jsonObject=JSON.parseObject(ss);

String hhString=jsonObject.getString("a");

JSONArray ssssArray=(JSONArray) JSONArray.parse(hhString);
System.out.println(ssssArray.get(0));



}

 三:

Map mapsMap=new HashMap<>();
mapsMap.put("1", 2);
mapsMap.put("2", 3);
Map<Object, Map> map=new HashMap<Object, Map>();

map.put("a", mapsMap);
map.put("b", mapsMap);
String ss=JSON.toJSONString(map);

 System.out.println(ss);

String hhString=jsonObject.getString("a");

System.out.println(hhString);

}

json数据的转换

原文地址:https://www.cnblogs.com/cws-kf/p/8630615.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved