3 回答
TA贡献1828条经验 获得超3个赞
您需要先使用,然后才能以所需的任何方式使用数据json_decode
示例(注意:不是最干净的做事方式):
/* Decode JSON */
$data = '{"sub":{"insert_id":[161,162,163,164],"venue_id":["21","3","5","6"]}}';
$subData = json_decode($data,true);
/* Just Loop Through Values */
foreach ($subData['sub']['insert_id'] as $sub){
echo ("<li>$sub</li>");
}
/* Create New Json */
$insertIdJson = json_encode($subData['sub']['insert_id']);
$venueIdJson = json_encode($subData['sub']['venue_id']);
echo ("Insert IDs: $insertIdJson </br>");
echo ("Venue IDs :$venueIdJson </br>");
/* Create Array Of insert_id */
$insertIdArray = json_decode(json_encode($subData['sub']['insert_id']),true);
$venueIdArray = json_decode(json_encode($subData['sub']['venue_id']),true);
var_dump($insertIdArray);
echo("</br>");
var_dump($venueIdArray);
TA贡献1900条经验 获得超5个赞
让我们考虑$json结果变量中的 json 响应
$json_result = "sub": {
"insert_id": [
161,
162,
163,
164
],
"venue_id": [
"21",
"3",
"5",
"6"
]
}
$result = json_decode($json_result, true);
$insert_id = $result["sub"]["insert_id"];
$venue_id = $result["sub"]["venue_id"];
echo "insert_id";
print_r($insert_id);
echo "venue_id";
print_r($venue_id);
TA贡献1712条经验 获得超3个赞
you can use this.
$jsonData = '{"sub":{"insert_id":[161,162,163,164],"venue_id":["21","3","5","6"]}}';
$json_result = json_decode($jsonData,true);
$insertId = $json_result["sub"]["insert_id"];
$venueId = $json_result["sub"]["venue_id"];
echo "<pre>";
print_r($insertId);
echo "<br>";
print_r($venueId);
- 3 回答
- 0 关注
- 78 浏览
添加回答
举报