Answer the question
In order to leave comments, you need to log in
How to work with json correctly?
There is a file with streams json/liveu.json
{ "streams" : {
"stream1": { "alive" : 0, "iframe" : "address?id-1 " },
"stream2": { "alive" : 1, "iframe" : "address?id-2" },
}
Please tell me how to display them in ifreme or another player, so that when the video is available it will show one picture, when another is not available.
alive = active and inactive stream.
Answer the question
In order to leave comments, you need to log in
var a = {"streams": {
"stream1": {"alive":0, "iframe":"адрес?id-1"},
"stream2": {"alive":1, "iframe":"адрес?id-2"},
"stream3": {"alive":1, "iframe":"адрес?id-3"}
}}
var res = [];
for (k in a.streams) {
// перебираем a.streams по ключам
if (a.streams[k].alive == 1) {
console.log('активно');
res.push(a.streams[k]); // собираем массив с alive == 1
} else {
console.log('не активно');
}
}
console.log(res[0]); // выводим первое значение из массива с alive == 1
How to draw a conclusion you decide for yourself, because it very much depends on the specific player and so on.
JSON can be converted to a regular object using the JSON.parse() function:
https://developer.mozilla.org/en/docs/Web/JavaScri...
Example:
var json_data = '{ "streams" : { "stream1": { "alive" : 0, "iframe" : "адрес?id-1 " }, "stream2": { "alive" : 1, "iframe" : "адрес?id-2" },}';
var data = JSON.parse(json_data);
// теперь в переменной дата обычный объект
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question