简体   繁体   中英

json_encode returning null on array

I'm trying to json_encode a php array however the "choices" part is returning 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}

any ideas why?

Edit: full code:

$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);

json_encode expects all content that you're encoding to be valid UTF-8. If any part of the content isn't proper UTF-8, json_encode will fail silently for that part (b

All string data must be UTF-8 encoded.

My guess is that the marks isn't properly UTF-8 encoded (but originates from a CP1252 based encoding).

See json_last_error to retrieve the last error code from the json module.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM