$ .getJSON数组

时间:2018-07-06 15:20:44

标签: javascript arrays getjson

我想做的是根据JSON响应构建一个数组。 我不确定自己在做什么错。数组以某种方式构建,但是我无法访问诸如active_team_members [0];

之类的元素

对我在做什么错有任何想法吗?

谢谢。

htmlwidgets::saveWidget
var active_team_members = getJsonUsers(); 
console.log(active_team_members[0]); // this returns "undefined"

var x_active_team_members = [1,2,3,4,5];
console.log(x_active_team_members[0]); // this works

console.log(active_team_members); //returns some kind of array? If you check your browser console you can see the array but it differs from the one below

console.log(x_active_team_members); //this is a normal array


function getJsonUsers() {

	var members = [];

	$.getJSON( "http://www.json-generator.com/api/json/get/bZjdjoFLvS?indent=2", function( data ) {

		$.each( data, function( key, val ) {
			$.each( val, function( k, v ) {

				members.push(parseInt(v.user.uid));

			});
		});

	});  

	return members;

}

0 个答案:

没有答案