json_encode is returning NULL?

前端 未结 10 1866
[愿得一人]
[愿得一人] 2020-11-22 12:22

For some reason the item \"description\" returns NULL with the following code:



        
10条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-22 12:42

    If you have at least PHP 5.5, you can use json_last_error_msg(), which will return a string describing the problem.

    If you don't have 5.5, but are on/above 5.3, you can use json_last_error() to see what the problem is.

    It will return an integer, that you can use to identify the problem in the function's documentation. Currently (2012.01.19), the identifiers are:

    0 = JSON_ERROR_NONE
    1 = JSON_ERROR_DEPTH
    2 = JSON_ERROR_STATE_MISMATCH
    3 = JSON_ERROR_CTRL_CHAR
    4 = JSON_ERROR_SYNTAX
    5 = JSON_ERROR_UTF8
    

    These can change in future versions, so it's better to consult the manual.

    If you are below 5.3, you are out of luck, there is no way to ask what the error was.

提交回复
热议问题