我不确定这是否会被视为json结构的正确格式。基本上我想要的是一组关联数组。我的json数据:
{
"notifications": [{
"notificationid": "7hstyans",
"notificationtitle": "Some alert title",
"notificationtype": "SPECIAL ALERT",
"dateCreated": "1502203175"
}, {
"notificationid": "9ksh7dh2",
"notificationtitle": "This is a old notification",
"notificationtype": "OLD ALERT",
"dateCreated": "1502138431"
}, {
"notificationid": "iksnudo3",
"notificationtitle": "new notification",
"notificationtype": "SOME ALERT",
"dateCreated": "1501000523"
}]
}
我正在寻找一种方法来访问它,例如data.notifications[0]["notificationid"]
这会被认为是json的正确格式以及访问它的正确方法还是格式化这种格式的最佳方法?
答案 0 :(得分:2)
只需使用json_decode即可。 例如:
$data = json_decode($jsonString, true);
echo $data['notifications'][0]['notificationid'];