Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I decode UTF8 characters using jQuery?

I recently just solved the issue of outputting foreign characters using utf8_decode function in this thread: How do I convert, display and store this characters in PHP?

It works by directly echoing the results out but now I have this json_encode function to pass to jquery for the results. Json_encode is escaping my data to something like this:

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

How do I json_decode from jquery? Thank you for any advice.

like image 982
pakito Avatar asked Feb 24 '23 18:02

pakito


1 Answers

jQuery offers the parseJSON method straight from the jQuery object:

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

For fetching data via AJAX, though, $.getJSON will run this internally and pass the result of $.parseJSON as the request's final result.

like image 182
Matchu Avatar answered Feb 26 '23 08:02

Matchu