2014-12-30 3 views
0

"선택"부분이 null을 반환하지만 PHP 배열을 json_encode하려고합니다.배열에 null을 반환하는 json_encode

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); 
+0

는 소리하지 않습니다 값 –

+1

그 점을 이해합니다. 왜 그런지 알아 내려고하는 중이 야. – user2570937

+0

분명히 해줄 수 있겠 니? : print_r 등의 첫 줄 ('Array ...')이 무엇입니까? 해당 배열을 정의하는 방법을 보여줍니다. 당신은 그 따옴표 전부를 도주하는 것을 확인하고 있는가? – philtune

답변

1

json_encode는 유효한 UTF-8로 인코딩하고 모든 내용을 기대하고있다. 내용의 일부가 적절한 UTF-8이 아닌 경우,로 json_encode 그 부분에 대해 자동으로 실패합니다 (

b를 모든 문자열 데이터는 UTF-8로 인코딩되어야합니다.

내 생각이 있다는 것입니다 마르크 제대로 UTF-8 인코딩 (하지만 CP1252 기반 인코딩에서 유래).

json으로 모듈에서 마지막 오류 코드를 검색 할 수 json_last_error를 참조하십시오.이 텍스트를 좋아하지 않는처럼

+0

메신저 bool (JSON_ERROR_UTF8에 사실), 내 열은 utf8_general_ci입니다. "UTF-8로 올바르게 표시 할 수있는 방법은 무엇입니까? – user2570937

+0

관련 부분은 MySQL 연결의 문자 집합입니다. UTF8로 설정되어 있지 않은 경우 (SET NAMES"utf8 "또는 PDO 또는 mysqli의 charset 속성 사용)) 삽입과 검색 모두에서 fscked 인코딩을 얻을 수있다. iconv를 사용하여 하나의 charset을 다른 charset으로 변환 할 수 있으며, 필요하다면 재귀 적으로 수행 할 수있다. – MatsLindh

+0

mysqli_set_charset ($ con, "utf8"); worked – user2570937