删除双引号和方括号JSON

时间:2022-09-15 16:01:12

I am retrieving info from Amazon API with my server file (node.js)

我正在使用我的服务器文件(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);
})

Then I use <td ng-repeat="att in amazon.ItemAttributes" >{{att.Title}}</td> to display some data from the app.get but it displays like this

然后我使用 {{att.Title}} 来显示app.get中的一些数据,但它显示如下

["Corsair Vengeance LPX 16GB (2x8GB) DDR4 DRAM 2400MHz (PC4-19200) C14 Memory Kit - Black"]

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

with "" and [] around the data, I tried with .replace but no luck

在数据的“”和[]周围,我尝试了.replace,但没有运气

Pastebin: http://pastebin.com/Ee8Aryw3

Any Ideas, Thank You

任何想法,谢谢

2 个解决方案

#1


0  

Use a $filter with .slice().

使用带有.slice()的$ filter。

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>

#2


0  

this is the filter for remove some chars:

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

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

in your html:

在你的HTML中:

{{item | clearText}}

#1


0  

Use a $filter with .slice().

使用带有.slice()的$ filter。

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>

#2


0  

this is the filter for remove some chars:

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

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

in your html:

在你的HTML中:

{{item | clearText}}