在有效的JSON JSON.parse错误 [英] JSON.parse Error on Valid JSON
问题描述
这JSON解析业务快把我逼疯了!我的JSON是有效的,因为当我通过JSONLint运行它,我得到的绿色标签说有效的JSON,但出于某种原因,我仍然无法通过我的角度控制器解析JSON。
This JSON parsing business is driving me crazy! My JSON is valid, because when I run it through JSONLint, I get the green label saying Valid JSON, yet for some reason I still cannot parse the JSON via my Angular Controller.
JSON code可以这里找到。
JSON code can be found here.
控制器code:
savvyApp.controller('ProductsCtrl', function($scope) {
var apiJSONResult = '<linked json here>';
$scope.apiResult = JSON.parse(apiJSONResult);
});
任何帮助将大大AP preciated。
Any help would be greatly appreciated.
推荐答案
这应该是答案。总之,你不能只是复制粘贴JSON和单引号引用它,期望它的工作。您还需要确保反斜线都设有codeD。
That should be the answer. In short you cannot just copy paste JSON and quote it in single quotes and expect it to work. You would also need to make sure the backslashes are encoded.
因此,JSON的是的实际上是有效的。但它不再是有效的,如果你把它复制粘贴到一个js文件。它有做怎样的javascript连接字符串中的codeS反斜杠。
So the JSON is in fact valid. But it is no longer valid if you copy paste it into a js file. It has to do with how javascript encodes backslashes in strings.
这篇关于在有效的JSON JSON.parse错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!