Angularjs 导出到CSV和导入到IndexedDB时的额外引号

Angularjs 导出到CSV和导入到IndexedDB时的额外引号,angularjs,csv,lodash,indexeddb,papaparse,Angularjs,Csv,Lodash,Indexeddb,Papaparse,我正在导出和导入一个包含嵌套数组的对象数组,在这个过程中使用ngCSV、loDash和PapaParse 该数组如下所示: [ { arrival:"15.34.59", cancelled:"", comments:[{message: "test", commenttime: "15.34", $$hashKey: "object:552"}] date:"27/09/2016" }, {

我正在导出和导入一个包含嵌套数组的对象数组,在这个过程中使用ngCSV、loDash和PapaParse

该数组如下所示:

[
    {
        arrival:"15.34.59",
        cancelled:"",
        comments:[{message: "test", commenttime: "15.34", $$hashKey: "object:552"}]
        date:"27/09/2016"
    },
    {
        arrival:"16.32.59",
        cancelled:true,
        comments:[]
        date:"27/09/2016"
    }
]
date,comments,arrival,cancelled
27/09/2016,"[{""message"":""testing"",""commenttime"":""14.52"",""$$hashKey"":""object:50""}]",14.52.29,,
27/09/2016,[],,TRUE
单击以下按钮时:

<button 
    ng-csv="commenttoJson(filteredRecords)" 
    csv-header="['date', 'comments', 'arrival', 'cancelled']" 
    filename="{{ createCsvFilename(dates) }}">
        Download
</button>
生成的文件如下所示:

[
    {
        arrival:"15.34.59",
        cancelled:"",
        comments:[{message: "test", commenttime: "15.34", $$hashKey: "object:552"}]
        date:"27/09/2016"
    },
    {
        arrival:"16.32.59",
        cancelled:true,
        comments:[]
        date:"27/09/2016"
    }
]
date,comments,arrival,cancelled
27/09/2016,"[{""message"":""testing"",""commenttime"":""14.52"",""$$hashKey"":""object:50""}]",14.52.29,,
27/09/2016,[],,TRUE
然后,我继续使用以下函数导入它:

$scope.onFileSelect = function ($files) {
  Papa.parse($files[0], {
    header: true,
    skipEmptyLines: true,
    complete: function(results, $files,err) {
      if (err) {
          console.log('err ', err);
      }
      $scope.parseddata = results.data;
    }
  });
};

$scope.importData = function () {
  $indexedDB.openStore('records', function(store){
    store.insert($scope.parseddata).then(function(e){
      store.getAll().then(function(record) {  
        $scope.recordlist = record;
        console.log($scope.recordlist);
        $('.import-data').modal('hide');
        $scope.deleted = false;
      });
    });
  });
};
问题是,它完美地导入了所有内容(除了注释),这些内容现在看起来如下所示,显然前端无法正确阅读:

[
    {
        arrival:"15.34.59",
        cancelled:"",
        comments:"[{"message":"test","commenttime":"15.34","$$hashKey":"object:552"}]"
        date:"27/09/2016"
    }, (...)
显然,在这个过程中,我遗漏了一些东西,因为所有额外的引号把我的代码弄乱了

有没有办法解决这个问题

编辑和修复 显然,我必须重新解析JSON以反转字符串化,并去掉数组中的额外引号

$scope.onFileSelect = function ($files) {
  Papa.parse($files[0], {
    header: true,
    skipEmptyLines: true,
    complete: function(results, $files,err) {
        if (err) {
            console.log('err ', err);
        }

    $scope.filteredRecordsToImport = _.map(results.data, function(item){
        return _.extend(item, {comments: item.comments ? JSON.parse(item.comments) : []});
    });
    console.log($scope.filteredRecordsToImport);

    }
  });
};

显然,我必须重新解析JSON以反转字符串化,并去掉数组中的额外引号

旁注…不会解决报价问题,但使用
angular.copy(object/array)
删除
$$hashkey
属性如果不字符串化
记录,会发生什么。注释
?看起来它正在字符串化一个已经是json的字符串,这个字符串会产生额外的引号,修复了它!我必须在导入时再次解析JSON以反转stringify!
$scope.onFileSelect = function ($files) {
  Papa.parse($files[0], {
    header: true,
    skipEmptyLines: true,
    complete: function(results, $files,err) {
        if (err) {
            console.log('err ', err);
        }

    $scope.filteredRecordsToImport = _.map(results.data, function(item){
        return _.extend(item, {comments: item.comments ? JSON.parse(item.comments) : []});
    });
    console.log($scope.filteredRecordsToImport);

    }
  });
};