如何从snapdeal json api获取数据只有特定的关联数组元素

时间:2017-01-10 15:41:12

标签: php json api curl

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

以下是代码:

<?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}

但我只想要标题和描述细节。我怎么能得到那些?

1 个答案:

答案 0 :(得分:0)

您可以访问您的数组,如:

$result['title']

$result['description']

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