2016-09-29 1 views
-3

왜 코드가 작동하지 않는지 알 수 없으므로 json으로 인코딩해야합니까? 내가 안드로이드 스튜디오에서 응용 프로그램에서이 PHP 코드 링크를 호출 의하지 작업 및 디스플레이 오류 메시지가,이 코드를 표시합니다 같은 jsonlint 웹 사이트에 디스플레이도json parse error on line 1 : < html >< body >

<html> <body> < script type = "text/javascript" 
src = "/aes.js" > < /script><script>function toNumbers(d){var e=[];d.replace(/ (..)/g, 
function(d) { 
    e.push(parseInt(d, 16)) 
}); 
return e 
} 
function toHex() { 
for (var d = [], d = 1 == arguments.length && arguments[0].constructor == Array ? arguments[0] : arguments, e = "", f = 0; f < d.length; f++) e += (16 > d[f] ? "0" : "") + d[f].toString(16); 
return e.toLowerCase() 
} 
var a = toNumbers("f655ba9d09a112d4968c63579db590b4"), 
b = toNumbers("98344c2eee86c3994890592585b49f80"), 
c = toNumbers("fafd97787619720460a70e34d00aedb4"); 
document.cookie = "__test=" + toHex(slowAES.decrypt(c, 2, a, b)) + "; expires=Thu, 31-Dec-37 23:55:55 GMT; path=/"; 
location.href = "http://gmarket.byethost5.com/json_getS.php?i=2"; 

를 위의 테스트는 PHP URL 및이 오류를 반환 할 때 :

라인 1

해석 에러 : < HTML> < body> <^"STRING ' 'NUMBER ','NULL '을 기대'TRUE ','FALSE ','{ ','[ ' , '정의되지 않음')

01 23,516,

이 PHP를 링크 : http://gmarket.byethost5.com/json_getS.php

이 PHP 코드는 내가 사용 : 귀하의 JSON이 올바른지

<?php 
$host= "sql201.byethost5.com"; 
$user = "xxxxxxx"; 
$pass = "xxxxxxx"; 
$db = "xxxxxxx"; 

$sql="select * from customer"; 

$con = mysqli_connect($host,$user,$pass,$db); 
$result= mysqli_query($con,$sql); 

$response = array(); 

while ($row = mysqli_fetch_array($result)) 
{ 

array_push($response,array("name"=>$row[0],"phone"=>$row[1])); 
} 
echo json_encode(array("customers"=>$response)); 

mysqli_close($con); 
?> 
+0

URL은 json을 반환합니다. 문제는 Android 코드에있는 것처럼 보입니다 – Jens

+0

'$ response = array(); 동안 ($ 행 = mysqli_fetch_array ($ 결과)) { $ 응답 [ '고객 [= 어레이 ("이름"=> $ 행 [0], "전화"=> $ 행 [1]); } echo json_encode ($ response); ' –

답변

0

이 문제가 당신이 내용이 JSON되는 브라우저를 이야기하지 않는, 당신의 반환 HTML입니다.

사용

header('Content-Type: application/json'); 
echo json_encode($response); 
+0

앱에서 사용했는데 아무 것도 변경되지 않았습니다. 동일한 문제> – Nawaf

0

내가 다른 웹 호스팅 도메인 (000webhost)와 같은 코드에 문제없이 작업을 사용, 난 (byethost)이 아닌 코드에서의 문제를 생각합니다.