Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何访问JSON内部的数组?_Json_Laravel_Rest_Guzzle - Fatal编程技术网

如何访问JSON内部的数组?

如何访问JSON内部的数组?,json,laravel,rest,guzzle,Json,Laravel,Rest,Guzzle,我正在使用Guzzle for Laravel为Web服务发送帖子,但我无法访问数组来发送图片。这就是我需要遵循的结构: { "title": "xxxxxxxxxxxxxxxxx", "category_id": "XXXX", "official_store_id": null, "pictures": [ { "id": "XXXXX", "url": "http://mlb-s1-p.mlstatic.com/292325-MLB25432321923_032017-O.jpg",

我正在使用Guzzle for Laravel为Web服务发送帖子,但我无法访问数组来发送图片。这就是我需要遵循的结构:

{
"title": "xxxxxxxxxxxxxxxxx",
"category_id": "XXXX",
"official_store_id": null,
"pictures": [
  {
"id": "XXXXX",
"url": "http://mlb-s1-p.mlstatic.com/292325-MLB25432321923_032017-O.jpg",
"secure_url": "https://mlb-s1-p.mlstatic.com/292325-MLB25432321923_032017-O.jpg",
"size": "500x500",
"max_size": "500x500",
"quality": ""
}
],
}
我试着这样发送:

 $r = $client->request('POST', 'https://api.mercadolibre.com/items?access_token='.$token->erp_access_token, [
                'json' => [
                    'title' => $name,
                    'category_id' => $cat2,
                    'price' => $price,
                    'currency_id' => 'BRL',
                    'available_quantity' => $quantity,
                    'buying_mode' => 'buy_it_now',
                    'listing_type_id' => 'gold_special',
                    'condition' => 'new',
                    'description' => $description,
                    'pictures' => [
                        'url' => $image
                    ]
                ]
            ]);
返回错误:

{"message":"body.invalid_field_types","error":"[invalid property type: [pictures] expected List but was JSONObject value (truncated...)
我读过Guzzle的文档,但是我没有找到任何关于这个案例的例子


有什么建议吗?

从此更改图片值

'pictures' => [
    'url' => $image
]
对此

'pictures' => [
    ['url' => $image]
]