How can I decode UTF8 characters using jQuery?

Recently, I just solved the problem of outputting foreign characters using the utf8_decode function in this thread: How can I convert, display and save these characters in PHP?

It works by directly reflecting the results, but now I have a json_encode function to jump to jquery for the results. Json_encode speeds up my data like this:

{"title":"\u90ed\u5bcc\u57ce - \u641c\u7d22"} 

How to json_decode from jquery? Thanks for any advice.

+4
source share
3 answers

Either you write it directly in JS, in which case you are not doing anything, or you are using one of the ajax methods in jQuery, in which case just specify dataType as "json"

+2
source

jQuery offers a parseJSON method directly from a jQuery object:

 var data = $.parseJSON('{"title":"\u90ed\u5bcc\u57ce - \u641c\u7d22"}'); 

To retrieve data via AJAX, $.getJSON will run this internally and pass the result of $.parseJSON as the final result of the request.

+5
source

to try

 var obj = JSON.parse('{"title":"\u90ed\u5bcc\u57ce - \u641c\u7d22"}'); 
+1
source

All Articles