目录
前言:
Java获取:
前言:
更新一波....... 马上要到月底啦 加油
群友提问回答
array.tostring 如何变成json 获取id....
前端获取:var str = "[{id:'ywglzhgl_account_system_0',text:'BASS',isLeaf: true,_click: true},{id:'ywglzhgl_account_system_543',text:'BOMC',isLeaf: true,_click: true},{id:'ywglzhgl_account_system_2',text:'BOSS',isLeaf: true,_click: true},{id:'ywglzhgl_account_system_3',text:'CRM',isLeaf: true,_click: true},{id:'ywglzhgl_account_system_4',text:'P-BOSS',isLeaf: true,_click: true},{id:'ywglzhgl_account_system_5',text:'u5176u4ED6u7CFBu7EDF',isLeaf: true,_click: true},{id:'ywglzhgl_account_system_6',text:'BOSSu6D4Bu8BD5u7CFBu7EDF',isLeaf: true,_click: true}]" 如何把所有的id元素给提取出来呢?
var str = "[{id:'ywglzhgl_account_system_0',text:'BASS',isLeaf: true,_click: true},{id:'ywglzhgl_account_system_543',text:'BOMC',isLeaf: true,_click: true},{id:'ywglzhgl_account_system_2',text:'BOSS',isLeaf: true,_click: true},{id:'ywglzhgl_account_system_3',text:'CRM',isLeaf: true,_click: true},{id:'ywglzhgl_account_system_4',text:'P-BOSS',isLeaf: true,_click: true},{id:'ywglzhgl_account_system_5',text:'u5176u4ED6u7CFBu7EDF',isLeaf: true,_click: true},{id:'ywglzhgl_account_system_6',text:'BOSSu6D4Bu8BD5u7CFBu7EDF',isLeaf: true,_click: true}]"; var json1=eval("("+str+")"); var h2=""; json1.forEach((item,index,array)=>{ //执行代码 h2+=item.id+";n" }) console.log(h2)
Java获取:eval("("+str+")");
String str ="[{id:'ywglzhgl_account_system_0',text:'BASS',isLeaf: true,_click: true},{id:'ywglzhgl_account_system_543',text:'BOMC',isLeaf: true,_click: true},{id:'ywglzhgl_account_system_2',text:'BOSS',isLeaf: true,_click: true},{id:'ywglzhgl_account_system_3',text:'CRM',isLeaf: true,_click: true},{id:'ywglzhgl_account_system_4',text:'P-BOSS',isLeaf: true,_click: true},{id:'ywglzhgl_account_system_5',text:'u5176u4ED6u7CFBu7EDF',isLeaf: true,_click: true},{id:'ywglzhgl_account_system_6',text:'BOSSu6D4Bu8BD5u7CFBu7EDF',isLeaf: true,_click: true}]";
String[] ids = str.split("id");
ArrayList
list = new ArrayList<>();
for (int i = 1; i < ids.length; i++) {
list.add(ids[i].substring(ids[i].indexOf("'", 0)+1, ids[i].indexOf("'", 2)));
}
Arrays.stream(ids).forEach(i->{
System.out.println(i);
});
list.stream().forEach(i->{
System.out.println(i);
});
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)