Saturday 18 March 2017

How can i decode unicode string in javascript

I have a string like \uC88B\uC544\uC694.
In a node repl(v7.4.0), this statement shows '좋아요' correctly. but in below code, it's not working.

var request = require('request');

request.post(
  {
    url: 'http://book.daum.net/dwr/call/plaincall/ajaxDetailController.getReviewListByPageNo.dwr',
    form: {
      callCount: 1,
      'c0-id': 0,
      'c0-scriptName': 'ajaxDetailController',
      'c0-methodName': 'getReviewListByPageNo',
      'scriptSessionId': '${scriptSessionId}714',
      'batchId': 6,
      'c0-param0': 'Object_Object:{bookid: KOR9791186757093, pageNo: 1, pageSize: 6}'
  }
}, 
(error, response, body) => {
  var str = 's2';
  var regex = new RegExp(str + `.\\w*\\=[\\"\\w\\d\\s\\\\\\&\\:\\/\\.]*\\;`, 'g');
  const arr= body.match(regex);
  /* HERE */
  console.log(arr[14].split('"')[1]);
  console.log(arr[25].split('"')[1]);
  console.log(arr[41].split('"')[1]);
  console.log(arr[35].split('"')[1]);
  console.log(arr[44].split('"')[1]);
  console.log(arr[13].split('"')[1]);
}
);

Why it doesn't show the correct string?



via dali high

No comments:

Post a Comment