php json_encode returning null

前端 未结 4 1857
情歌与酒
情歌与酒 2020-12-11 03:47
Array
(
    [sEcho] => 1
    [iTotalRecords] => 7521
    [iTotalDisplayRecords] => 1
    [aaData] => Array
        (
            [0] => Array
                 


        
相关标签:
4条回答
  • 2020-12-11 04:27

    Actually it doesn't return null, http://codepad.org/A34KdUf5.

    Maybe your PHP version doesn't support json_encode().

    0 讨论(0)
  • 2020-12-11 04:32

    From the manual:

    Note that if you try to encode an array containing non-utf values, you'll get null values in the resulting JSON string. You can batch-encode all the elements of an array with the array_map function:

    $encodedArray = array_map(utf8_encode, $myArr);
    echo json_encode($encodedArray);
    
    0 讨论(0)
  • 2020-12-11 04:47

    Works for me on 5.2.13. Ensure you're using at least PHP 5.2.0 and that PHP wasn't compiled with --disable-json. You may also want to check that error reporting (and/or logging) is enabled.

    0 讨论(0)
  • 2020-12-11 04:52

    The simpler way is $store_name = utf8_encode(name_of_varaible) but please make sure that your character set is ISO-8859-1.

    0 讨论(0)
提交回复
热议问题