Reputation: 65
My JSON file is like this and I want to read this file in PHP:
{
"data": [
{
"time": 1383458400,
"summary": "Mostly cloudy throughout the day.",
},
{
"time": 1383458400,
"summary": "Mostly cloudy throughout the day.",
}
],
"data": [
{
"time": 1383458400,
"summary": "Mostly cloudy throughout the day.",
},
{
"time": 1383458400,
"summary": "Mostly cloudy throughout the day.",
}
]
}
How can I read this file in PHP? I am using the following to read:
$str = file_get_contents('files/filenameme.json');
$json = json_decode($str, true);
Upvotes: 0
Views: 71
Reputation:
Did you write the JSON by yourself?
You have two problems there: the "data" is a duplicate, and this should be unique like "data1", "data2". The other problem is the comma after the summary part -- it doesn't belong there.
If you fix these issues you should be good to go.
Upvotes: 1