PHP变量的JSON键/值

PHP变量的JSON键/值,php,arrays,json,parsing,foreach,Php,Arrays,Json,Parsing,Foreach,我会直截了当地说 我正在尝试使用以下方法保存从API检索的数据: $i=0; foreach($results->results as $product){ $products[$i]['pid'] = $product->listing_id; $products[$i]['title'] = $product->title; $products[$i]['url'] = $product-

我会直截了当地说

我正在尝试使用以下方法保存从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 $5, 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 $2-Ships within 1 business day. Please allow 2-5 business days for delivery.\r\nIntl S&H is $4 - 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
是一个对象数组,
image

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

$product->results[0]->Images[0]->url_75x75
在您的代码中,这显然是错误的:

$product->results.Images[url_75x75]

混合了PHP语法的Javascript?;-)

你的问题标题是一回事,你的文本中的问题完全不同,你的JSON与你的描述不匹配(你有图像URL,而不是图像)-你能更清楚一点问题是什么吗?我只是在回顾我的问题后编辑了标题,我道歉。我想将“url_x”值保存到变量中。我无法在我的foreach中实现此功能。您收到一个错误,或者它只是没有插入?我收到的错误是:Parse error:syntax error,unexpected'['在第18行的/home/theendst/public_html/mysite.com/etsyapi/etsyapi/include/pull_listing_data.php中,这不是完整的代码,这是我遇到问题的foreach。我的数据库中没有图像url的结果。这就像代码在object中没有看到任何值一样?啊,你没有使用PHP5.4?Capsule,我玩过您的回答和结果是:
$product->Images[0]->url_75x75
是正确的方法,谢谢您和所有回答我问题的人!:)啊,是的,在我的示例中,$product是解码的JSON对象