阅读日志时,JSON从双引号更改为单引号

通过apache日志(下面),我可以parsing出一个JSON:

[2014.02.14_21.24.22.543] other info I don't care about json: { "petstore": "store_number_8", "dogs":{ "terrier":{ "total":2 } }, "cat":{ "siamese":{ "total":5 } } } 

1)这是有效的JSON? 2)为什么双引号变成单引号?

读完之后,parsing出JSON并显示出来,我得到以下结果:

 { 'petstore': 'store_number_8', 'dogs':{ 'terrier':{ 'total':2 } }, 'cat':{ 'siamese':{ 'total':5 } } } 

顺便说一下,我使用Node.js的fs.createStream来读取日志,然后只是做一个控制台(到目前为止,我没有做任何消毒,最终我会写它到一个文件)。

 fs.creatReadStream(logs).pipe(split()).on(data, function(line){ if(line.match(/json\:/)){ shouldThisBeValidJSON = JSON.parse(line.slice(line.indexOf('{'), line.length)); console.log(shouldThisBeValidJSON); } 

先谢谢你。

console.log不会返回JSON。 它返回这个对象的可读表示。

所以不,这不是JSON,更接近于JSON5。

如果要显示JSON,则必须将string传递给console.log,即console.log(JSON.stringify(shouldThisBeValidJSON))