can any one help me parse the below json
{
"success": 1,
"channel": [
{
"id": "11",
"name": "chan",
"img": "images",
"stream_url": "url",
"stream_url2": "url",
"stream_url3": "url",
"cat_id": "1"
},
{
"id": "132",
"name": "Name",
"img": "images",
"stream_url": "mainurl",
"stream_url2": "stream2",
"stream_url3": "stream3",
"cat_id": "1"
}
]
}
im stuck when it comes to multiple arrays. the json returns about 30 arrays
I’m a bit stuck understanding what you’re asking for? If you just want to turn this into an associative array, you probably only need to do
$parsed = json_decode($jsonString, true);
The true flag casts the return value to an array (otherwise, it’d be an object that you get back due to its multi-dimensional structure)
After parsing, you can access the elements like this
$firstChannel = $parsed['channel'][0]; // php arrays are zero-indexed
$streamUrl2FromSecondChannel = $parsed['channel][1]['stream_url2'];
Did that help? The ‘30 arrays’ bit is the thing that’s confusing… 
haha cheers dude i used the following worked it out @ midnight ha
$data = json_decode($jsonBytes);
foreach($data->channel as $category_name => $products) {
$chaname = $products->name;
$chanurl = $products->stream_url3;
}
system
Closed
4
This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.