E_Jovi E_Jovi - 5 months ago 23
Javascript Question

how could I display normal char?

I use es6 fetch and get response, but I find that some string display incorrect like

"name":"\\u5b5f\\u6587\\u4e54"
.

how could I fix it?

Answer

Call JSON.parse on your resulting json string:

var resString = '{"name":"\\u5b5f\\u6587\\u4e54"}';
var res = JSON.parse(resString);

console.log(res);
console.log(res.name);

Alternatively, since you are using fetch and retrieving JSON, there's a good chance you maybe be able to just use the .json() method on the response object.

Example:

yourFetchPromise.then(function(res) {
  return res.json(); // Process result as json here
}).then(function(data) {
  // use data here as a JS object
});

Fiddle: https://jsfiddle.net/vqe5kv1g/1/