値を抽出してPHP変数に割り当てるのに必要な次のJSONファイルがあります。必要な値は "icn"です。PHPでJSONを解析し、変数に代入する
{
"apiVersion": "1.0",
"data": {
"updated": 20160331141332,
"totalItems": 1,
"currentItemCount": 1,
"items": [
{
"birthDate": "20171101",
"fullName": "DOE,JOHN D",
"icn": "889081784V888383",
"pid": "55R1;60004"
}
]
}
}
私は以下を試したが、結果は得られなかった。
$myjson = file_get_contents('http://testurl.org/info.json');
print_r(json_decode($myjson->data->items[0]->icn,true));
echo "<br>LAST-Error:"; echo json_last_error();
echo "<br>LAST-Error-Msg:"; echo json_last_error_msg();
結果は
LAST-Error:0
LAST-Error-Msg:No error
可能な複製を(http://stackoverflow.com/questions/29308898/how-do -i-extract-data-from-json-with-php) –