我提到了一个奇怪的行为:
这是我的源字符串:{"data":{"allowfullscreen":true,"duration":0,"keyboard":false,"imgclass":"","hrefclass":""},"images":[{"src":"storage/home-hero.jpg","alt":"Home hero"}]}
现在我这样做了:
parsed = {};
try {
parsed = JSON.parse(data.matches[1]);
} catch (e) {}
console.log(JSON.parse(data.matches[1]));
console.log(parsed);
结果应该是一样的,对吧?
但输出结果不同:
输出#1(JSON.parse(data.matches[1]);
)
Object
data: {allowfullscreen: true, duration: 0, keyboard: false, imgclass: "", hrefclass: ""}
images: [{src: "storage/home-hero.jpg", alt: "Home hero"}]
和输出#2(parsed
):
Object
images: Array (1)
0 {src: "storage/home-hero.jpg", alt: "Home hero", __v-for__8: null}
为什么他们不一样?