I can’t use json return in php

Asked

Viewed 234 times

-1

Good morning guys, I’m having following problem, using a php api.

I make a call that calls me back : inserir a descrição da imagem aqui

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

1 answer

1

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

Try it this way:

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

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

Whereas:

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
  • Thanks, it worked!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.