首页 新闻 会员 周边 捐助

json字符串转成数组

0
悬赏园豆:40 [已解决问题] 解决于 2018-09-04 18:40

var pz_copy =
{"7":{"id":13,"name":"zhuanyi","url":"pic/G/zhuanyi.jpg"},"15":{"id":8,"name":"kangshengsu","url":"pic/G/kangshengsu.jpg"},"19":{"id":10,"name":"gaowen","url":"pic/G/gaowen.jpg"},"20":{"id":2,"name":"DNAlianjiemei","url":"pic\/J\/DNAlianjiemei.jpg"},"23":{"id":6,"name":"PCR","url":"pic\/J\/PCR.jpg"},"24":{"id":12,"name":"ziwaixian","url":"pic/G/ziwaixian.jpg"},"26":{"id":3,"name":"gujiazaiti","url":"pic\/J\/gujiazaiti.jpg"},"29":{"id":4,"name":"mudijiyin","url":"pic\/J\/mudijiyin.jpg"},"31":{"id":4,"name":"mudijiyin","url":"pic\/J\/mudijiyin.jpg"},"32":{"id":6,"name":"PCR","url":"pic\/J\/PCR.jpg"},"33":{"id":12,"name":"ziwaixian","url":"pic/G/ziwaixian.jpg"},"34":{"id":9,"name":"kangxingjiyin","url":"pic/G/kangxingjiyin.jpg"},"35":{"id":2,"name":"DNAlianjiemei","url":"pic\/J\/DNAlianjiemei.jpg"},"36":{"id":2,"name":"DNAlianjiemei","url":"pic\/J\/DNAlianjiemei.jpg"},"38":{"id":6,"name":"PCR","url":"pic\/J\/PCR.jpg"},"39":{"id":4,"name":"mudijiyin","url":"pic\/J\/mudijiyin.jpg"},"40":{"id":7,"name":"shijunti","url":"pic/G/shijunti.jpg"},"41":{"id":5,"name":"xijun","url":"pic\/J\/xijun.jpg"},"42":{"id":5,"name":"xijun","url":"pic\/J\/xijun.jpg"},"43":{"id":4,"name":"mudijiyin","url":"pic\/J\/mudijiyin.jpg"},"44":{"id":1,"name":"neiqiemei","url":"pic\/J\/neiqiemei.jpg"},"45":{"id":11,"name":"hesuanshuijiemei","url":"pic/G/hesuanshuijiemei.jpg"},"46":{"id":5,"name":"xijun","url":"pic\/J\/xijun.jpg"},"47":{"id":2,"name":"DNAlianjiemei","url":"pic\/J\/DNAlianjiemei.jpg"},"48":{"id":4,"name":"mudijiyin","url":"pic\/J\/mudijiyin.jpg"},"49":{"id":3,"name":"gujiazaiti","url":"pic\/J\/gujiazaiti.jpg"},"50":{"id":5,"name":"xijun","url":"pic\/J\/xijun.jpg"},"51":{"id":3,"name":"gujiazaiti","url":"pic\/J\/gujiazaiti.jpg"},"52":{"id":1,"name":"neiqiemei","url":"pic\/J\/neiqiemei.jpg"},"53":{"id":1,"name":"neiqiemei","url":"pic\/J\/neiqiemei.jpg"},"54":{"id":8,"name":"kangshengsu","url":"pic/G/kangshengsu.jpg"},"55":{"id":2,"name":"DNAlianjiemei","url":"pic\/J\/DNAlianjiemei.jpg"},"56":{"id":4,"name":"mudijiyin","url":"pic\/J\/mudijiyin.jpg"},"57":{"id":7,"name":"shijunti","url":"pic/G/shijunti.jpg"},"58":{"id":11,"name":"hesuanshuijiemei","url":"pic/G/hesuanshuijiemei.jpg"},"59":{"id":6,"name":"PCR","url":"pic\/J\/PCR.jpg"},"60":{"id":6,"name":"PCR","url":"pic\/J\/PCR.jpg"},"61":{"id":10,"name":"gaowen","url":"pic/G/gaowen.jpg"},"62":{"id":10,"name":"gaowen","url":"pic/G/gaowen.jpg"},"63":{"id":8,"name":"kangshengsu","url":"pic/G/kangshengsu.jpg"}};

网上的实在看蒙了,本身就不是很懂。哪位大神能帮我把这个字符串转化成js可调用的数组,并且把id前面的那个数字(就是索引值?)给去掉。比较急,先谢过。

vic~的主页 vic~ | 初学一级 | 园豆:27
提问于:2018-09-04 16:14
< >
分享
最佳答案
1

var pz_copy={
"7": {
"id": 13,
"name": "zhuanyi",
"url": "pic/G/zhuanyi.jpg"
},
"15": {
"id": 8,
"name": "kangshengsu",
"url": "pic/G/kangshengsu.jpg"
}
};

var arr = [];
for(var field in pz_copy){
arr.push(pz_copy[field]);
}

收获园豆:30
大豆男生 | 小虾三级 |园豆:608 | 2018-09-04 18:31
其他回答(1)
0

$.parseJSON 转成对象
然后
var arr = []
for (let i in obj) {
arr.push(obj[i]); //属性
}; 转数组

收获园豆:10
让我发会呆 | 园豆:2929 (老鸟四级) | 2018-09-04 16:36

$.parseJSON是jQuery的用法吧,我用JSON.parse()应该是一样的吧。然后在let提示目前版本不支持,那我改成var也一样是吧,但是我却得不到结果,而且我看是不是还没删除索引值

支持(0) 反对(0) vic~ | 园豆:27 (初学一级) | 2018-09-04 16:50

@vic~: 我就在当前页面,打开开发者工具,运行下来最终是一个数组。
当你已经拿到数组了,那既可以拿到其中的每一个对象了,然后再重新定义新对象,只把nam和url赋值进去就行了啊。

支持(0) 反对(0) 让我发会呆 | 园豆:2929 (老鸟四级) | 2018-09-04 17:05
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册