A
A
Alexander Zhukalin2019-12-26 22:00:48
JavaScript
Alexander Zhukalin, 2019-12-26 22:00:48

JSON file from facebook, how to display russian text?

I exported a file with posts from the FB community in JSON format. Instead of displaying Russian texts there
\u00d0\u00a4\u00d0\u00be\u00d1\u0082\u00d0\u00be \u00d0\u00b8\u00d0\u00b7 \u00d1\u0085\u00d1\u0080\u00d0\u00be\u00d0\u00bd\u000b u00d0\u00ba\u00d0\u00b8.
On stackoverflow , I found a way to convert to readable data using PHP:

$json = changeCharset(json_decode($str, TRUE));

var_dump($json);

function changeCharset( $array ){
    array_walk_recursive( $array, function(&$item) { 
       $item = iconv("UTF-8", "ISO-8859-1", $item); 
    });
    return $array;
}

I can't understand why we are converting from UTF-8 to ISO-8859-1, and how can I convert the json file so that it can be viewed by a standard editor without resorting to converting using a PHP function.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vladislav Orlov, 2019-12-26
@al3xru

Try to use the JSON_UNESCAPED_UNICODE parameter when you get your json file
Here is the whole line:
$json = json_encode($return_info, JSON_UNESCAPED_UNICODE);
I used to have this problem myself. Decided just like that.

I
Ilya Savinykh, 2019-12-27
@IsSavinykh

$json = utf8_encode($str); 
$results = json_decode($json, TRUE);
var_dump($json);

OR as mentioned above
$json = json_decode(json_encode($str, JSON_UNESCAPED_UNICODE), TRUE);
var_dump($json);

As of PHP 7.2.0, the utf8_encode function has been moved to PHP core, thus removing the requirement for an XML extension to use this function.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question