JSON KEY/VALUE 到 PHP 变量

JSON KEY/VALUE to PHP variable

开门见山

我正在尝试使用以下方法保存从 API 检索到的数据:

$i=0;
foreach($results->results as $product){
    $products[$i]['pid']            = $product->listing_id;
    $products[$i]['title']          = $product->title;
    $products[$i]['url']            = $product->url;
    $products[$i]['price']          = $product->price;
    $products[$i]['quantity']       = $product->quantity;
    $products[$i]['endtime']        = $product->ending_tsz;
$products[$i]['thumb']          = $product->results.Images[url_75x75];

这是 JSON 请求:

{
   "count":163,
   "results":[
      {
     "listing_id":118973432,
     "state":"active",
     "user_id":27549667,
     "category_id":68894752,
     "title":"Funny I Love You Valentines Card - I Heart you Even More then a Nerd Loves Starwars - Adult Funny Humor Greeting Cards",
     "description":"You know how much Nerds be loving the Star Wars , this Valentines day show the one you love that you love them even more then that - The perfect greeting card for that special someone!\r\n\r\nGUARANTEED CHRISTMAS DELIVERY - Place your orders by 12\/19 and get it by Christmas Eve - Upgraded Two Shipping available starting at , just contact us to upgrade\r\n\r\nDetails:\r\n\r\n- Outside Message: I love you even more then a nerd loves Starwars\r\n- Inside Message: Blank Inside\r\n- Size A7 (5x7)\r\n- Matching White Envelope included \r\n- Packaged in a cello sleeve for protection in transit\r\n\r\nWe will gladly ship to your recipient! Just specify a ship to address and any special message in "notes to seller" at checkout.  Need a Custom Card, Magnet or keychain, we do that too!\r\n\r\nShipping:\r\nUS S&H is -Ships within 1 business day. Please allow 2-5 business days for delivery.\r\nIntl S&H is  - Ships within 1 business day - Please allow 7-10 business days for delivery.\r\n\r\nBuy MORE and SAVE on shipping! Express shipment is available to most US cities contact us for price and details.\r\n\r\nFor More Rude, crude and downright funny greeting cards, novelty gifts and prints, visit our Etsy store and browse a large selection single cards, greeting card sets, prints and more totally edgy, racy, adult, crass, lude, perverted and all things nasty!\r\nimjustsayininc.etsy.com",
     "creation_tsz":1422565585,
     "ending_tsz":1432929985,
     "original_creation_tsz":1356746393,
     "last_modified_tsz":1422565585,
     "price":"4.00",
     "currency_code":"USD",
     "quantity":3,
     "tags":[
        "funny card",
        "greeting card",
        "novelty card",
        "mature card",
        "adult card",
        "cards",
        "funny cards",
        "relationship card",
        "love card",
        "i love you card",
        "valentines cards",
        "funny valentine",
        "valentines day card"
     ],
     "category_path":[
        "Paper Goods",
        "Cards",
        "Valentine"
     ],
     "category_path_ids":[
        69150367,
        69152963,
        68894752
     ],
     "materials":[
        "Papaer",
        "Ink",
        "Envelope"
     ],
     "shop_section_id":12656719,
     "featured_rank":null,
     "state_tsz":1421921498,
     "url":"https:\/\/www.etsy.com\/listing\/118973432\/funny-i-love-you-valentines-card-i-heart?utm_source=massetsy&utm_medium=api&utm_campaign=api",
     "views":764,
     "num_favorers":102,
     "shipping_template_id":null,
     "processing_min":1,
     "processing_max":1,
     "who_made":"i_did",
     "is_supply":"false",
     "when_made":"2010_2015",
     "is_private":false,
     "recipient":"unisex_adults",
     "occasion":"valentines",
     "style":null,
     "non_taxable":false,
     "is_customizable":true,
     "is_digital":false,
     "file_data":"",
     "language":"en-US",
     "has_variations":false,
     "used_manufacturer":false,
     "Images":[
        {
           "listing_image_id":410447372,
           "hex_code":"C1AFB1",
           "red":193,
           "green":175,
           "blue":177,
           "hue":353,
           "saturation":9,
           "brightness":75,
           "is_black_and_white":false,
           "creation_tsz":1356746394,
           "listing_id":118973432,
           "rank":1,
           "url_75x75":"https:\/\/img0.etsystatic.com\/015\/0\/7566894\/il_75x75.410447372_sjo4.jpg",
           "url_170x135":"https:\/\/img0.etsystatic.com\/015\/0\/7566894\/il_170x135.410447372_sjo4.jpg",
           "url_570xN":"https:\/\/img0.etsystatic.com\/015\/0\/7566894\/il_570xN.410447372_sjo4.jpg",
           "url_fullxfull":"https:\/\/img0.etsystatic.com\/015\/0\/7566894\/il_fullxfull.410447372_sjo4.jpg",
           "full_height":737,
           "full_width":600
        },
        {
           "listing_image_id":402927400,
           "hex_code":"897761",
           "red":137,
           "green":119,
           "blue":97,
           "hue":33,
           "saturation":29,
           "brightness":53,
           "is_black_and_white":false,
           "creation_tsz":1356746394,
           "listing_id":118973432,
           "rank":2,
           "url_75x75":"https:\/\/img0.etsystatic.com\/003\/0\/7566894\/il_75x75.402927400_e80x.jpg",
           "url_170x135":"https:\/\/img0.etsystatic.com\/003\/0\/7566894\/il_170x135.402927400_e80x.jpg",
           "url_570xN":"https:\/\/img0.etsystatic.com\/003\/0\/7566894\/il_570xN.402927400_e80x.jpg",
           "url_fullxfull":"https:\/\/img0.etsystatic.com\/003\/0\/7566894\/il_fullxfull.402927400_e80x.jpg",
           "full_height":800,
           "full_width":986
        },
        {
           "listing_image_id":402923983,
           "hex_code":"C8C1C0",
           "red":200,
           "green":193,
           "blue":192,
           "hue":8,
           "saturation":4,
           "brightness":78,
           "is_black_and_white":false,
           "creation_tsz":1356746394,
           "listing_id":118973432,
           "rank":3,
           "url_75x75":"https:\/\/img1.etsystatic.com\/005\/0\/7566894\/il_75x75.402923983_snri.jpg",
           "url_170x135":"https:\/\/img1.etsystatic.com\/005\/0\/7566894\/il_170x135.402923983_snri.jpg",
           "url_570xN":"https:\/\/img1.etsystatic.com\/005\/0\/7566894\/il_570xN.402923983_snri.jpg",
           "url_fullxfull":"https:\/\/img1.etsystatic.com\/005\/0\/7566894\/il_fullxfull.402923983_snri.jpg",
           "full_height":440,
           "full_width":640
        }
     ]
  }
   ],
   "params":{
  "limit":"1",
  "offset":0,
  "page":null,
  "shop_id":"imjustsayininc",
  "keywords":null,
  "sort_on":"created",
  "sort_order":"down",
  "min_price":null,
  "max_price":null,
  "color":null,
  "color_accuracy":0,
  "tags":null,
  "category":null,
  "translate_keywords":"false",
  "include_private":0
   },
   "type":"Listing",
   "pagination":{
  "effective_limit":1,
  "effective_offset":0,
  "next_offset":1,
  "effective_page":1,
  "next_page":2
   }
    }

我想要做的是从显示图像的图像字段中提取所有值 URL (url_75x75,url_170x135,url_570xN & url_fullxfull).

我好像只卡在导入图片上。它们似乎在一个数组中,我不知道如何像处理其余内容一样实现拉动它们。

我花了大约 3 天的时间搜索、尝试并失败了。

当我将 Json 请求拆分为单独的请求时,我成功了,但最近了解到我可以将图像包含在一个 JSON 请求中,这是我目前正在尝试的方法。

我该怎么做?

我是 PHP 的新手,我在 JSON 上什至是新手,所以请尽可能描述一下,尽量不要用复杂的方法让我负担过重,谢谢.

results是对象数组,Images

也是

我没有测试,但我认为像这样的东西应该能够检索第一个结果的第一个图像:

$product->results[0]->Images[0]->url_75x75

在你的代码中,这显然是错误的:

$product->results.Images[url_75x75]

Javascript 和 PHP 语法混合在一起? ;-)