【问题标题】:how can I get data from snapdeal json api only specifc associative array elements如何从 snapdeal json api 仅获取特定关联数组元素的数据
【发布时间】:2017-01-10 15:41:11
【问题描述】:

我只想获取特定关联数组元素的数据。我怎样才能做到这一点?

代码如下:

<?php    

$ch = curl_init();
$id=647672630230;
curl_setopt($ch, CURLOPT_URL, "affiliate-feeds.snapdeal.com/feed/product?id=$id");
curl_setopt(
    $ch, CURLOPT_HTTPHEADER,
    array(
        'Snapdeal-Affiliate-Id:133419',
        'Snapdeal-Token-Id:cf72ba3b7c2f47e3e0b09cd7e8613c',
        'Accept:application/json'
    )
);

$response = curl_exec($ch);
curl_close($ch);

// work with $response here:
$result = json_decode($response, TRUE);


?>

它在$result中返回这个结果:

{"id":647672630230,"title":"Spacewood Carnival Queen Bed","description":"Non-cancellable: Order can't be cancelled after 48 hours Color : Wenge Ideal Mattress Size (L X B in cm) : Standard mattress size for bed: 150 x 195 cm (Mattress is not included in the sales package) Finish : Melamine Size : Queen Material: Particle Board Overall Height (cm)-80 cm, Overall Width (cm)-163 cm, Overall Depth (cm)-206 cm Queen Size Bed with No Storage Warranty: 12 Months Weight Bearing Capacity: 250 Kgs. Warranty: 36 Months Primary Material: Particle Board Size: Queen Ideal Mattress Size (L X B in cm):150 x 195 cm Finish: Melamine Colour: Wenge Disclaimer: The product colour may slightly vary due to lighting conditions or your monitor settings ","brand":"Spacewood","link":"http://www.snapdeal.com/product/spacewood-carnival-queen-bed/647672630230?utm_source=aff_prog&utm_campaign=afts&offer_id=17&aff_id=133419","imageLink":"http://n1.sdlcdn.com/imgs/b/x/u/Spacewood-Carnival-Queen-Bed-SDL572327220-1-034bf.jpg","subCategoryId":1195,"subCategoryName":"Beds","categoryId":580,"categoryName":"Furniture","mrp":20090,"offerPrice":8299,"effectivePrice":8299,"availability":"in stock","sizes":null,"colors":null,"walletCashback":0}

但我只想要标题和描述细节。我怎样才能得到这些?

【问题讨论】:

    标签: php json api curl


    【解决方案1】:

    你可以像这样访问你的数组:

    $result['title']

    $result['description']

    你可以通过我的测试看到这个工作: http://sandbox.onlinephpfunctions.com/code/be2f8f5152e217247a7f82f3a08f699976763995

    【讨论】:

    • 注意:如果我尝试这个尝试获取非对象的属性
    猜你喜欢
    • 1970-01-01
    • 2020-02-11
    • 2015-04-11
    • 2020-11-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-25
    • 1970-01-01
    相关资源
    最近更新 更多