douhei8633 2018-07-24 12:28
浏览 44

卷曲爬行 - 只是不能正确

So i am pullin item data and the rest

I am unable to get ItemDataCosts

I am pulling al the json thats not an array inside an array- but item data cost i am unable to get

If any body can point me in the correct direction

with

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

This is what is returned from 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)
    }
  }

and i get the json with below php curl - the output is wat i got then i take that and paste in http://jsonviewer.stack.hu and then format to view the fields

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);
  • 写回答

2条回答 默认 最新

  • duanjiao8871 2018-07-30 09:29
    关注

    ItemData (according to your array-ified JSON) is array. Using -> will not work on it, but $result->ItemData['ItemDataCosts'] should do. so this should work:

    $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>"; 
    
    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?