所以我要提取项目数据,其余的
我无法获得ItemDataCosts
我正在拉所有不是数组中的json的json,但是我无法获得项目数据成本
如果有人可以指向我正确的方向
与
echo "<br>ItemDataCosts start<br>";
foreach($result->ItemData->ItemDataCosts as $ItemDataCosts) {
echo $ItemDataCosts->Seq.'Seq<br>';
echo $ItemDataCosts->FUnitPrice.'FUnitPrice<br>';
echo $ItemDataCosts->Currencies_Seq.'Currencies_Seq<br>';
}
echo "<br>ItemDataCosts end<br>";
这是json返回的
"ItemData"
]=>array(4){
[
0
]=>array(46){
[
"BookStatus"
]=>int(3)[
"BookNotes"
]=>array(2){
[
"SupplierReference"
]=>string(0)""[
"Details"
]=>string(85)" Cancelled on: 7/23/2018 12:58:07 PM BRBK1H Booked on: 3/9/2018 1:15:23 PM "
}[
"Allocated"
]=>bool(false)[
"StartDate"
]=>string(20)"2018-08-05T14:00:00Z"[
"CostPriceCompo"
]=>NULL[
"GTABookingHeaders"
]=>array(0){
}[
"ProductTariff"
]=>NULL[
"QuoteProp"
]=>NULL[
"ItemDataCosts"
]=>array(1){
[
0
]=>array(19){
[
"Seq"
]=>float(720949)[
"ItemData_Seq"
]=>float(140)[
"UnitPrice"
]=>float(819)
}
}
然后我得到了php curl以下的json-输出是我得到的结果,然后我将其粘贴到http://jsonviewer.stack.hu中,然后格式化以查看字段
error_reporting(E_ALL);
ini_set('display_errors', 1);
$url = 'https://my.travpro.cloud/api//costings/getcosting/*****';
$auth = base64_encode('paul.******:******3');
$postfields = http_build_query( array(
'grant_type' => 'client_credentials'));
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_POSTFIELDS => $postfields,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_HTTPHEADER => array(
"Accept: application/json",
"Content-Type: application/x-www-form-urlencoded",
"Authorization: Basic $auth"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
$result = json_decode($response);
答案 0 :(得分:0)
ItemData(根据您的数组定义的JSON)是array。无法使用->
,但应该使用$result->ItemData['ItemDataCosts']
。
所以这应该工作:
$result = json_decode($response);
echo "<br>ItemDataCosts start<br>";
$itemData = $result->{'ItemData'};
foreach($itemData as $ItemData) {
foreach($itemData as $item) {
$itemDataCosts = $item->{'ItemDataCosts'};
foreach($itemDataCosts as $itemDataCost) {
echo $itemDataCost->{'Seq'} . 'Seq<br>';
echo $itemDataCost->{'FUnitPrice'} . 'FUnitPrice<br>';
echo $itemDataCost->{'Currencies_Seq'} . 'Currencies_Seq<br>';
}
}
}
echo "<br>ItemDataCosts end<br>";
答案 1 :(得分:0)
通过大量搜索找到了答案,这是行之有效的
$this_data = $result->ItemData;
foreach($this_data as $key){
foreach($key->ItemDataCosts as $values){
echo '<pre>';
echo $values->ItemData_Seq . ' ItemData Sequence';
echo $values->FUnitPrice . ' Unit Price';
echo '</pre>';
echo '<br/>';
}
}
die();