如果我将JSON.parse的结果存储在变量中,则获得不同的结果

时间:2018-01-29 20:06:35

标签: javascript json

我提到了一个奇怪的行为:

这是我的源字符串:{"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}

为什么他们不一样?

0 个答案:

没有答案