JSON 响应只转储一个结果而不是三个。
我需要以以下 json 格式获取 json 响应。它包含三个结果
{"entries":[{"id":"1A","content_no":101},
{"id":"1B","content_no":102},
{"id":"1C","content_no":103}
]}
当我根据 json 结果运行下面的代码时:
// curl result
//echo $result;
$json = json_decode($result, true);
// initial post variable
$post= [];
foreach($json['entries'] as $data){
// printed three result successfilly in for each loop
$id = $data['id'];
$content_no = $data['content_no'];
// Now to get the result in the required json format and dump it or echo it outside for each loop
$entries = array();
$entries['id'] = $data['id'];
$entries['content_no'] = data['content_no'];
$params = array();
$params['entries'][] = $entries;
$post = json_encode($params);
}
// send post result in json format to database
var_dump($post);
for each 循环打印 3 个结果,但我的问题是,根据下面的 json,只有一个结果是 var 转储的。我想知道其他 2 个结果隐藏在哪里。请问我如何根据上面的json格式获得剩余的2个结果
{"entries":[{"id":"1C","content_no":103}]}
Qyouu
慕少森
慕尼黑的夜晚无繁华