用php错误解析json;为foreach()提供的参数无效;

用php错误解析json;为foreach()提供的参数无效;,php,json,Php,Json,我在用php解析json提要时遇到问题,无法找出我做错了什么 JSON提要 [{"id":10428167,"url":"some_url","amount":1197,"price":0.37,"seller":{"id":4682621,"name":"Rap17ka7a"}}, {"id":10428466,"url":"some_url","amount":1450,"price":0.37,"seller":{"id":5031734,"name":"Meanor"}}, {"id":

我在用php解析json提要时遇到问题,无法找出我做错了什么

JSON提要

[{"id":10428167,"url":"some_url","amount":1197,"price":0.37,"seller":{"id":4682621,"name":"Rap17ka7a"}},
{"id":10428466,"url":"some_url","amount":1450,"price":0.37,"seller":{"id":5031734,"name":"Meanor"}},
{"id":10429969,"url":"some_url","amount":109,"price":0.37,"seller":{"id":5862543,"name":"djeisanborn"}}]
PHP解析器

$request_url ="json_feed_url_is_here";
$requests = file_get_contents($request_url);
$response = json_decode($requests);
foreach ($response as $item) {
$seller = $item->seller->name;

$seller = str_replace("'", "'", $seller);
$seller = str_replace("’", "’;", $seller);


$sql = ("INSERT INTO table_name ( ~~~cell names~~~) 
        VALUES (~~~cell values~~~, '$item->amount', '$item->price', '$item->url')") or  die('<b>Data Insert Error:</b> ' . mysql_error());
if (!mysql_query($sql,$con1))
  {
  die('Error: ' . mysql_error());
  }
}

将的第二个参数设置为
true
,以将JSON转换为关联数组而不是对象

$response = json_decode($requests, true);

它已经是一个数组,因为它由
[]
包装。我通过运行代码来确认这一点。@ariefbayu你说得对,结果是一个对象数组。原始代码应该是正常的。@milenmk检查JSON是否只包含一个元素,这样它就不会被包装在
[]
中。e、 g:
{“id”:10428167,“url”:“some_url”,“amount”:1197,“price”:0.37,“seller”:{“id”:4682621,“name”:“Rap17ka7a”}
@bsdnoobz,所有10个元素都在[]
Var\u dump
调试结果内。显示文件start的十六进制摘录。您的php,
Var\u dump
请求
提供正常的数据输出
$response = json_decode($requests, true);