W
W
Worker132015-08-20 18:25:31
JSON
Worker13, 2015-08-20 18:25:31

Why is the wrong encoding saved in csv format?

The question is the following, there is a collection of Clients and you need to backup it to a csv file. After subscribing and clicking, you should:

$scope.saveAll = function(){
      function JSON2CSV(objArray) {
        var array = typeof objArray != 'object' ? JSON.parse(objArray) : objArray;
        var str = '';
        var line = '';
        for (var i = 0; i < array.length; i++) {
          var line = '';
            for (var index in array[i]) {
              var value = array[i][index] + "";
              line += '"' + value.replace(/"/g, '""') + '",';
            }
          line = line.slice(0, -1);
          str += line + '\r\n';
        }
        return str;
      }
      var jsonObject = JSON.stringify($scope.clients);
      var csv = JSON2CSV(jsonObject);
      window.open(encodeURI('data:text/csv;charset=utf-8,' + csv));
      console.log(csv);
    }

In the console log, everything looks good: screen
After saving the file, open it and see: screen
Encoding is specified, but it does not pull it up and we get krakozyabry. Actually, how can I get what I want in the file? Thanks in advance.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question