I can not use the json return in php

-1

Good morning, I have the following problem, using an api php.

I make a call that returns me:

Then when I give echo var_dump () says to be string (27398), I then do json_decode () and do a print_r (var_dump ()); and says NULL, so I have the following doubts, why when I call json it comes to variable but it gets untouchable when I do object- > offers for example? But I think it's because it turns NULL, but if it is because the object that in the request presents a json in the form of a string is transforming to NULL? I await your help. And thank you very much for your attention.

    
asked by anonymous 15.05.2017 / 10:43

1 answer

1

It seems that some non-utf-8 character in json is breaking its json_decode.

Try this:

  

$ json = json_decode (utf8_encode ($ jsonString), true);

You can also see what error occurred with your json_decode using the json_last_error () function if the php version is 5.3 or later.

Being that:

JSON_ERROR_NONE - Não ocorreu nenhum erro    
JSON_ERROR_DEPTH - A profundidade máxima da pilha foi excedida   
JSON_ERROR_STATE_MISMATCH - JSON inválido ou mal formado     
JSON_ERROR_CTRL_CHAR - Erro de caractere de controle, possivelmente codificado incorretamente    
JSON_ERROR_SYNTAX - Erro de sintaxe  
JSON_ERROR_UTF8 - caracteres UTF-8 malformado , possivelmente codificado incorretamente
    
15.05.2017 / 12:24