Angular和JSON,解析ng repeat时遇到问题
我非常抱歉,如果有这方面的帖子,我试图搜索,但没有找到答案 问题:Angular和JSON,解析ng repeat时遇到问题,json,angularjs,angularjs-ng-repeat,Json,Angularjs,Angularjs Ng Repeat,我非常抱歉,如果有这方面的帖子,我试图搜索,但没有找到答案 问题: "[{\"type\":\"2\",\"number\":\"VHT3866\",\"location\":\"Delta\",\"destinationNo\":\"\",\"contactName\":\"Jesus\",\"shipToName\":\"Lord jesus\",\"highPriority\":\"false\",\"hasComment\":\"true\",\"assignedTo\":\"\",\"
"[{\"type\":\"2\",\"number\":\"VHT3866\",\"location\":\"Delta\",\"destinationNo\":\"\",\"contactName\":\"Jesus\",\"shipToName\":\"Lord jesus\",\"highPriority\":\"false\",\"hasComment\":\"true\",\"assignedTo\":\"\",\"source\":\"\"},{\"type\":\"2\",\"number\":\"VHT3866\",\"location\":\"Delta\",\"destinationNo\":\"\",\"contactName\":\"Jesus\",\"shipToName\":\"Lord jesus\",\"highPriority\":\"false\",\"hasComment\":\"true\",\"assignedTo\":\"\",\"source\":\"\"}]"
我正在调用一个web服务并从Dynamics Nav服务接收格式不太好的JSON数据:
JSON:
"[{\"type\":\"2\",\"number\":\"VHT3866\",\"location\":\"Delta\",\"destinationNo\":\"\",\"contactName\":\"Jesus\",\"shipToName\":\"Lord jesus\",\"highPriority\":\"false\",\"hasComment\":\"true\",\"assignedTo\":\"\",\"source\":\"\"},{\"type\":\"2\",\"number\":\"VHT3866\",\"location\":\"Delta\",\"destinationNo\":\"\",\"contactName\":\"Jesus\",\"shipToName\":\"Lord jesus\",\"highPriority\":\"false\",\"hasComment\":\"true\",\"assignedTo\":\"\",\"source\":\"\"}]"
然后我使用这个JSON并使用angular.fromJson(JSON)
正确地获取它
它似乎没有变成javascript对象数组,只是纯文本
但是,如果我使用相同的JSON并手动将其放入,如下所示:
var json = angular.fromJson(stringfromserver);
它会变成一个合适的javascript对象,并且
ng repeat
不会抛出错误。我在Quora上找到了一个答案:
---巴图尔酒店,
json中的Angular现在是严格的,因此假设该字符串来自可信源,则必须使用“eval()”并将调用括在括号中才能使其工作
var hatsData=angular.fromJson(eval(“(“+hats+”))例如,如果从http请求获取JSON,则不需要使用fromJson方法
JSON由Angular自动解析,您可以直接使用它。我在Quora上找到了一个答案:---Le Batoure,,Angular from JSON现在是严格的,所以假设这个字符串来自可信的源,您必须使用“eval()”加上括号中的调用,它才能工作var hatsData=Angular.fromJson(eval(“)“+hats+”)---你可以回答自己,而不只是发表评论。很高兴知道。谢谢教授,我对这一点非常陌生,回答了这个问题:)但是在angular 1.3.0中没有
eval
,它对我来说很好。可能它与你的主耶稣有关:)主耶稣只是被插入而不是实际的公司名称,不想公开显示:)我的angular实际上是1.2.17,要更新它,看看它是否重要。