JSON_ENCODE编码包含的php文件的内容

问题描述:

JSON_ENCODE有一个奇怪的问题。我使用PHP从数据库中检索数据,并使用JSON将其传递给Javascript。直到我包含另一个我打算用于在数据返回之前对数据进行处理的php文件,它才能完美工作。包含文件JSON开始编码返回的数据和我包含的文件的内容。JSON_ENCODE编码包含的php文件的内容

PHP代码:就是从这个文件返回

<?php 
    include("GeoLocation.php");//STATEMENT CAUSING JSON TO ACT WEIRDLY 
    $dbhost = "localhost"; 
    $dbuser = "root"; 
    $dbpass = ""; 
    $dbname = "go_with_your_mood"; 

     //$lat=(isset($_GET['lat']))?$_GET['lat']:''; 
     //$long=(isset($_GET['long']))?$_GET['long']:''; 


    //$geo = new GeoLocation(); 


$mysqli = new mysqli('127.0.0.1', $dbuser, $dbpass, $dbname); 
//Select Database 
//mysql_select_db($dbname) or die(mysql_error()); 

//build query 
$query = "SELECT * FROM service where service_type = 'security' limit 5"; 

//Execute query 
$qry_result = $mysqli->query($query); 

//initial array to encapsulate each individual row 
$jsonArray = array(); 

// Insert a new array for each row returned 
while($row = $qry_result->fetch_assoc()){ 
    $rowArray = array($row["id"],$row["name"],$row["address"],$row["suburb"],$row["postcode"],$row["phone"],$row["latitude"],$row["longitude"],$row["description"],$row["service_type"]); 
    array_push($jsonArray, $rowArray); 
} 
echo json_encode($jsonArray); 
?> 

数据:

enter image description here

enter image description here

enter image description here

数据应该返回:

336,TERANG PUBLIC HOSPITAL,13 AUSTIN AVENUE,TERANG,3264,,-38.23939895629883000000,142.90240478515625000000,,medical, 
337,ALFRED PUBLIC HOSPITAL,55 COMMERCIAL ROAD,MELBOURNE,3004,,-37.84560012817383000000,144.98210144042970000000,,medical, 
338,CAULFIELD PUBLIC HOSPITAL,260 KOOYONG ROAD,CAULFIELD,3162,,-37.88240051269531000000,145.01669311523438000000,,medical,339,NORTHERN PUBLIC HOSPITAL,185 COOPER STREET,EPPING,3076,,-37.65259933471680000000,145.01510620117188000000,,medical,340,MAFFRA PUBLIC HOSPITAL,42-48 KENT STREET,MAFFRA,3860,,-37.96120071411133000000,146.98339843750000000000,,medical 

有谁知道为什么JSON会返回包含文件的内容以及我的数据?

看起来像短标签<?已禁用。并且看起来像您的geolocation.php文件以<?开头,而不是<?php 请编辑您的geolocation.php文件并在开始时用<?php代替<?

或者包括像以下

include('GeoLocation.php'); 

含义包括它的前,后把空间或复制粘贴包括代码它上面写的。希望这些解决方案之一可以工作。

或者,如果您可以启用短标签。

+0

就是这样。感谢您的快速解决。 :) – user2787386