删除双引号和方括号JSON

时间:2016-05-04 21:40:26

标签: javascript angularjs json

我正在使用我的服务器文件(node.js)从Amazon API检索信息

client.itemLookup({
  idType: 'ISBN',
  itemId: 'B00S51XHUQ, B00P3IX4V6',
  responseGroup: 'Offers,ItemAttributes'
}).then(function(results){
    res.send(JSON.stringify(results));
  console.log(results);
})

然后我使用<td ng-repeat="att in amazon.ItemAttributes" >{{att.Title}}</td> 从app.get显示一些数据,但它显示如下

[&#34; Corsair Vengeance LPX 16GB(2x8GB)DDR4 DRAM 2400MHz(PC4-19200)C14内存套件 - 黑色&#34;]

与&#34;&#34;和[]围绕数据,我尝试.replace但没有运气

Pastebin:http://pastebin.com/Ee8Aryw3

任何想法,谢谢

2 个答案:

答案 0 :(得分:0)

$filter.slice()一起使用。

var app = angular.module("app", []);

app.controller("MainCtrl", ["$scope", function($scope){
	$scope.item = "[\"Corsair Vengeance LPX 16GB (2x8GB) DDR4 DRAM 2400MHz (PC4-19200) C14 Memory Kit - Black\"]";
  
  //$scope.hello = "hello world";
}]);

app.filter("cleanItem", function() {
	return function(input) {
  	if(!input) return "";
    
    return input.slice(2, -2);
  }
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="app" ng-controller="MainCtrl">
{{item | cleanItem}}
</div>

答案 1 :(得分:0)

这是删除一些字符的过滤器:

 app.filter('clearText', function() {
        return function(text) {
          return  text ? String(text).replace(/"<[^>]+>/gm, '') : '';
       }
      });
你的HTML中的

{{item | clearText}}
相关问题