0
http://services.xyz.com/tours.asmx/Sample?type=2&CityID=1146&days=4この配列データをHTMLに表示したいとします。私はこのエラーを取得していますJSON配列foreachループforeach()の引数が無効です。
ini_set("display_errors", 1);
$url = "http://services.xyz.com/tours.asmx/Sample?type=2&CityID=1146&days=4";
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
//curl_setopt($ch, CURLOPT_POSTFIELDS, $fields); // set the fields to post
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // make sure we get the response back
$xml = curl_exec($ch); // execute the post
curl_close($ch); // close our session
include "XMLParser.php";
$parser = new XMLParser();
$tour = $parser->parseString($xml);
print_r($tour);
//$errors = array_filter($tour);
if (empty($tour)) {
echo 'Error';
}else{
echo 'No Error';
}
//print_r($xml);
//var_dump($xml);
//echo $xml;
//$xmlfile = file_get_contents($tour);
$ob= simplexml_load_string($tour);
//$json = json_encode($ob);
$configData = json_decode($ob, true);
foreach($configData as $result){
echo '<tr>';
echo '<td>'.$result->name.'</td>';
echo '<td>'.$result->phone.'</td>';
echo '<td>'.$result->email.'</td>';
echo '</tr>';
}
Warning: Invalid argument supplied for foreach() in C:
私を助けてください:
は、ここに私のコードです。 ありがとう
配列が空です。ループする前に確認してください – Akintunde007
コードの画像は問題では受け入れられません。実際のコードはここに入れてください – apokryfos
おそらく 'json_encode'ではなく' json_decode'が必要です。そのAPIはすでにJSON文字列を与えているからです。 24行目を取り除き、現在の25行目に '$ json'を' $ ob'に置き換えます(新しい行24になります)。 – ccKep