无法打印json输出

时间:2018-09-07 04:25:56

标签: php json web-services

我将此文件保存在Web服务器上,并且位于authentication.php中,但是我无法使用此文件在Web浏览器中显示json输出数据。当我在网络浏览器中加载它时,没有输出或错误...请帮助我。

  

authentication.php是服务器和此文件的XML Web服务   从该文件获取数据,现在的问题是,我正在尝试转换   传入的数据到json并使用发送到Google表格   google appscript,该应用程序脚本应捕获json格式


<?php 
// Boutique_Hotels_web_srv
require_once('authentication.php');

//print_r($key);
$result = $client->UseService(array('Key' => $key, 'ServiceName' => 'Boutique_Hotels_web_srv'))->UseServiceResult;
//print_r($result);

$data = array();
$data = $result->string;
$wtst_id = 1;

if(count($data) > 0){
$db->query("DELETE FROM " . DB_PREFIX . "where_to_stay WHERE wtst_id = '" . (int)$wtst_id . "' "); 
}

foreach($data as $data=>$hotel){
$hotel_data = explode('|', $hotel);

$tags = '';
if($hotel_data[18] == 'True'){
$tags .= ', Night Life';
}
if($hotel_data[19] == 'True'){
$tags .= ', Ballooning';
}
if($hotel_data[20] == 'True'){
$tags .= ', Diving, Snorking';
}
if($hotel_data[21] == 'True'){
$tags .= ', Golf';
} 
if($hotel_data[22] == 'True'){
$tags .= ', Surfing';
}
if($hotel_data[23] == 'True'){
$tags .= ', Fishing';
}
if($hotel_data[24] == 'True'){
$tags .= ', Caving';
}
if($hotel_data[25] == 'True'){
$tags .= ', Water Skiing';
}
if($hotel_data[26] == 'True'){
$tags .= ', Rock Climbing';
}
if($hotel_data[27] == 'True'){
$tags .= ', kayaking, canoeing';
}
if($hotel_data[28] == 'True'){
$tags .= ', wildlife safari';
}
if($hotel_data[29] == 'True'){
$tags .= ', agro tourism';
}
if($hotel_data[30] == 'True'){
$tags .= ', whale and dolphin watching';
}
if($hotel_data[31] == 'True'){
$tags .= ', White water rafting';
}
if($hotel_data[32] == 'True'){
$tags .= ', Shopping';
}

return $hotel;

$myObj->hotel__data0 =$hotel_data[0];
$myObj->hotel__data10 =$hotel_data[10];
$myObj->hotel__data32 =$hotel_data[32];

$myJSON = json_encode($myObj);

echo $myJSON;

}

?>

1 个答案:

答案 0 :(得分:0)

好吧,我解决了,由fb小组VasileŢucă帮助了我

<?php 
// Boutique_Hotels_web_srv
require_once('authentication.php');

//print_r($key);
$result = $client->UseService(array('Key' => $key, 'ServiceName' => 'Boutique_Hotels_web_srv'))->UseServiceResult;
//print_r($result);

$data = array();
$data = $result->string;
$wtst_id = 1;

if(count($data) > 0){
$db->query("DELETE FROM " . DB_PREFIX . "where_to_stay WHERE wtst_id = '" . (int)$wtst_id . "' "); 
}

foreach($data as $data=>$hotel){
$hotel_data = explode('|', $hotel);

$tags = '';
if($hotel_data[18] == 'True'){
$tags .= ', Night Life';
}
if($hotel_data[19] == 'True'){
$tags .= ', Ballooning';
}
if($hotel_data[20] == 'True'){
$tags .= ', Diving, Snorking';
}
if($hotel_data[21] == 'True'){
$tags .= ', Golf';
} 
if($hotel_data[22] == 'True'){
$tags .= ', Surfing';
}
if($hotel_data[23] == 'True'){
$tags .= ', Fishing';
}
if($hotel_data[24] == 'True'){
$tags .= ', Caving';
}
if($hotel_data[25] == 'True'){
$tags .= ', Water Skiing';
}
if($hotel_data[26] == 'True'){
$tags .= ', Rock Climbing';
}
if($hotel_data[27] == 'True'){
$tags .= ', kayaking, canoeing';
}
if($hotel_data[28] == 'True'){
$tags .= ', wildlife safari';
}
if($hotel_data[29] == 'True'){
$tags .= ', agro tourism';
}
if($hotel_data[30] == 'True'){
$tags .= ', whale and dolphin watching';
}
if($hotel_data[31] == 'True'){
$tags .= ', White water rafting';
}
if($hotel_data[32] == 'True'){
$tags .= ', Shopping';
}

$myObj["hotel_data0"] = $hotel_data[0];
$myObj["hotel_data10"] = $hotel_data[10];
$myObj["hotel_data32"] = $hotel_data[32];

$myJSON = $myObj;

var_dump($myJSON);


}

?>              

这是正确的代码