json_encode在数组上返回null

时间:2014-12-30 22:27:05

标签: php json

我试图json_encode一个php数组然而"选择"部分返回null。

Array ( [indexer] => 7 [section] => 1 [question] => What does the last paragraph indicate about an optimistic perspective? [answer] => a [choices] => There has never been a culture or religion that is genuinely optimistic`It is “a riddle of the universe”`No enlightened culture sees the world in a truly optimistic manner`Optimistic perspectives are only held by the weak )

{"indexer":"7","section":"1","question":"What does the last paragraph indicate about an optimistic perspective?","answer":"a","choices":null}

任何想法为什么?

编辑:完整代码:

$check = mysqli_query($con, "select * from questions where section = '$section' and indexer = '$question'");
$result = mysqli_fetch_array($check, MYSQLI_ASSOC);

print_r($result);
echo json_encode($result);

1 个答案:

答案 0 :(得分:1)

json_encode期望您编码的所有内容都是有效的UTF-8。如果内容的任何部分不是正确的UTF-8,那么json_encode将无声地失败(b

  

所有字符串数据必须采用UTF-8编码。

我的猜测是标记未正确编码UTF-8(但源自基于CP1252的编码)。

请参阅json_last_error以从json模块中检索最后一个错误代码。