i am trying to get few strings from json but with no success yet :(
i tried many codes but still no luck and can't understand this fully
the json example is :
{
"nginx_version": "1.7.11.3 Gryphon",
"nginx_rtmp_version": "1.1.4",
"built": "Mar 19 2015 20:36:41",
"pid": "4680",
"uptime": "1876",
"naccepted": "3",
"bw_in": "404904",
"bytes_in": "83699680",
"bw_out": "404912",
"bytes_out": "83700478",
"server": {
"application": [{
"name": "msdk",
"live": {
"stream": {
"name": "xkiz531",
"time": "1854519",
"bw_in": "399752",
"bytes_in": "82628640",
"bw_out": "399752",
"bytes_out": "82628588",
"bw_audio": "178480",
"bw_video": "221272",
"client": [{
"id": "2788",
"address": "example.com\/live\/live",
"time": "1854519",
"flashver": "ngx-local-relay",
"dropped": "0",
"avsync": "-14",
"timestamp": "1853566",
"active": []
}, {
"id": "2787",
"address": "197.14.103.17",
"time": "1854987",
"flashver": "FMLE\/3.0 (compatible; FMSc\/1.0)",
"swfurl": "rtmp:\/\/example.com\/msdk",
"dropped": "0",
"avsync": "-14",
"timestamp": "1853566",
"publishing": [],
"active": []
}],
"meta": {
"video": {
"width": "1280",
"height": "720",
"frame_rate": "30",
"codec": "H264",
"profile": "High",
"compat": "0",
"level": "3.1"
},
"audio": {
"codec": "AAC",
"profile": "LC",
"channels": "2",
"sample_rate": "44100"
}
},
"nclients": "2",
"publishing": [],
"active": []
},
"nclients": "2"
}
}, {
"name": "test",
"live": {
"nclients": "0"
}
}]
}
}
the code i have now is :
$array = json_decode($json,TRUE);
var_dump($array);
foreach($array['items'] as $item) {
echo $item['server']['application']['live']['stream']['name'];
}
i want to obtain the values of these keys on strings :
bw_audio, bw_video, width, height, frame_rate, codec, profile, audio codec & sample rate
itemsin the JSON.applicationis an array. You need to use['application'][0]or iterate over it.bw_audio,bw_video, or you want to get the values of those keys?$array['items']is. I assume the JSON you showed is$array.