E_Jovi E_Jovi - 1 year ago 79
Javascript Question

how could I display normal char?

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


how could I fix it?

Answer Source

Call JSON.parse on your resulting json string:

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


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.


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/

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download