M
M
Mechanic2015-12-19 18:43:07
PHP
Mechanic, 2015-12-19 18:43:07

Why doesn't json_decode work after iconv?

Hi friends. Please tell me why json_decode doesn't work after iconv?
The situation is this: there is a site in cp1251, there is a remote server that, via API (curl), gives JSON in utf-8. Naturally, the Cyrillic alphabet in it comes out as krakozyabry. For this I do:

$actions_converted = iconv("utf-8", "cp1251", curl_exec($ch));
$actions = json_decode($actions_converted);

NULL is written to $actions, but everything is written to $actions_converted as it should, i.e. conversion is successful.
I also tried like this:
$actions = json_decode(curl_exec($ch));
$actions_converted = iconv("utf-8", "cp1251", $actions);

The situation is similar, but now in $actions I get an object, i.e. everything is ok, but in $actions_converted - NULL.
Please, tell me what the plug is happening. Broke my whole head.
Many thanks and good karma to all who answered!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Robot, 2015-12-19
@bitrixweb

So it only works with utf-8
json_last_error() shows something?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question