javascript - JSON.parse 是如何工作的?

标签 javascript jquery json

console.log(this.item_images)
console.log(JSON.parse("["+this.item_images+"]"))

我想将 this.item_images 转换为数组并循环遍历它,为什么我无法解析它?以下是上述代码在控制台中的结果。注意:我 console.log(typeof this.item_images) 它是一个字符串。

enter image description here

最佳答案

this.item_images 似乎是一个只有一个元素的数组:字符串 '038...6aa'

所以我猜你可能想将字符串分割到另一个数组中。

var arr = this.item_images[0].split(',');

然后就可以循环数组arr了。

更新:如果 this.item_images 是字符串,请使用:

var arr = this.item_images.split(',');

相反。

关于javascript - JSON.parse 是如何工作的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31872979/

相关文章:

javascript - 同位素 Metafizzy : How to check if an element has already been initialized as an isotope container?

javascript - 更改时选择 - 获取数据

jquery - Bootstrap datepicker 2.0 在月 View 中显示日历

json - Elasticsearch多个术语可以促进

python - 如何使用 python3 将更改模式 json 插入 mysql 中?

javascript - Angular ui-router 中的绝对名称

javascript - 用于检查文本的 jquery 验证不包含 html

javascript - setTimeout 和 mouseout 问题

javascript - 使用 jquery 克隆 google 饼图会触发 XMLHttpRequest 错误

javascript - 只删除json对象中的父节点而不删除子节点