Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/406.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从Javascript函数返回JSON对象_Javascript_Json_Function_Object - Fatal编程技术网

从Javascript函数返回JSON对象

从Javascript函数返回JSON对象,javascript,json,function,object,Javascript,Json,Function,Object,尝试解析一些livestream JSON数据,并查看事件是否具有特定的标记。 如果没有,那么我将使用该数据来输出值,等等 无论出于何种原因,uncoming_event没有被分配事件对象(这是findPublicEvent函数的返回值) 事件对象的console.log工作正常-但返回它不起作用:/ // get our NLC data from livestream. // -> note: need the '?callback=?' to convert to JSONP for

尝试解析一些livestream JSON数据,并查看事件是否具有特定的标记。 如果没有,那么我将使用该数据来输出值,等等

无论出于何种原因,
uncoming_event
没有被分配事件对象(这是
findPublicEvent
函数的返回值)

事件对象的console.log工作正常-但返回它不起作用:/

// get our NLC data from livestream.
// -> note: need the '?callback=?' to convert to JSONP for cross-domain usage
var $uri = 'http://api.new.livestream.com/accounts/newlifechurchtv/?callback=?';
$.getJSON($uri, function(data) {
    parseNLCData(data);
});

parseNLCData = function(nlc_data){
  // set our variable to the return first event
  // nlc_data.upcoming_events.data is a json array of events
  window.upcoming_event = findPublicEvent(nlc_data.upcoming_events.data);
}

// should return single public event
function findPublicEvent (all_events) {
  // if we have events
  if (all_events) {
    // loop through events to find public event
    $.each(all_events, function(index,value){
      // get all the tags, remove whitespace, and put into array
      var $tags = value.tags.replace(/ /g, '').toLowerCase().split(',');
      // check for privacy.
      var $privacy = $.inArray('private', $tags);
      if ($privacy === -1) {
        // if the event isn't private -> return it!
        console.log(value);
        return value;
      }
    });
   // otherwise .... ->
   } else {
    // we don't have events, sooo, no dice.
    return false;
   }

 };

findPublicEvent
没有返回它。您传递给
每个
的匿名函数正在返回它

因为它是您正在捕获的
findPublicEvent
的返回值,所以您无法看到它

  • findPublicEvent
  • 从匿名函数内部为其赋值(使用常规赋值,而不是返回)
  • findPublicEvent

  • findPublicEvent
    没有返回它。您传递给
    每个
    的匿名函数正在返回它

    因为它是您正在捕获的
    findPublicEvent
    的返回值,所以您无法看到它

  • findPublicEvent
  • 从匿名函数内部为其赋值(使用常规赋值,而不是返回)
  • findPublicEvent