json parse error on line 1: < html > < body >

点点圈 提交于 2019-12-14 00:06:42

问题


i dont know why the code is not working, it should encode to json ? when i call this PHP code link from app in Android studio its not working and display error message ,it display this code :

< 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"; 

also in jsonlint website display same the above when test the php URL and return this error :

Parse error on line 1: < html > < body > < ^ Expecting 'STRING', 'NUMBER', 'NULL', 'TRUE', 'FALSE', '{', '[', got 'undefined')

this php link :http://gmarket.byethost5.com/json_getS.php

this php code i used:

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

回答1:


Your Json is correct, the issue is your returning HTML, you're not telling the browser that the content is Json.

Use

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



回答2:


i used another webhosting domain (000webhost) and its work without any problem with same code , i think the problem from (byethost) not from the code.



来源:https://stackoverflow.com/questions/39771091/json-parse-error-on-line-1-html-body

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!