2014-11-30 2 views
0

JSON을 사용하여 안드로이드 클라이언트에 배열 응답을 보내는 PHP 서버를 개발하고 있습니다. 이제 PHP 코드를 테스트하지만 결과는 비어 있습니다. 도와주세요!!빈 응답 PHP는 JSON

<?php 
      #Connect to Database 
      $con = mysqli_connect("localhost","root","", "leoonline"); 

      #Check connection 
      if (mysqli_connect_errno()) { 
       echo 'Database connection error: ' . mysqli_connect_error(); 
       exit(); 
      } 

      //Check already exist account 
      $allaccount = mysqli_query($con, "SELECT * FROM usersacc"); 
      $results = array(); 
      while($row = mysqli_fetch_array($allaccount)) 
      { 
       $results[] = array(
        'id' => base64_decode($row['id']), 
        'phone' => $row['phone'], 
        'password'> $row['password'] 
       ); 
      } 
      $json = json_encode($results); 

    ?> 
+0

if ($ allaccount) {while() {...} var_dump ($ json);} –

+0

테이블 usersacc에 필요한 데이터가 있습니까? – fortune

+0

이 답변을 읽기 : [https://stackoverflow.com/questions/17219916/json-decode-returns-json-error-syntax-but-online-formatter-says-the-json-is-ok] [1] [1] : https://stackoverflow.com/questions/17219916/json-decode-returns-json-error-syntax-but-online-formatter-says-the-json-is -승인 – toto21

답변

0

최종 코드입니까? 연결 오류 메시지가 발생하면 별도의 정보를 출력하지 않습니다.

변경

$json = json_encode($results); 

는 여전히 비어, 다음이 될 수있는 DB 데이터 문제의 경우

echo json_encode($results); 

합니다.