Reputation: 659
I tried alot of things, but nothing worked. I'm using jQuery.
So what I have to do is really to import http://jacce.dyndns.org/game/resources/game/map.php (so far I succeeded with $.getJSON), convert it to an array and then place it in a global variable.
I don't really know how to do any of the last two things (well, I know how to create global variables, but not inside jQuery functions). So, any help?
EDIT: Here's the JSON:
{
"-5": {
"-5": {
"id": "1",
"colour": ""
},
"-4": {
"id": "2",
"colour": ""
},
"-3": {
"id": "3",
"colour": ""
},
"-2": {
"id": "4",
"colour": ""
},
"-1": {
"id": "5",
"colour": ""
},
"1": {
"id": "6",
"colour": ""
},
"2": {
"id": "7",
"colour": ""
},
"3": {
"id": "8",
"colour": ""
},
"4": {
"id": "9",
"colour": ""
},
"5": {
"id": "10",
"colour": ""
}
},
"-4": {
"-5": {
"id": "11",
"colour": " fill=\"#A90000\""
},
"-4": {
"id": "12",
"colour": ""
},
"-3": {
"id": "13",
"colour": ""
},
"-2": {
"id": "14",
"colour": ""
},
"-1": {
"id": "15",
"colour": ""
},
"1": {
"id": "16",
"colour": ""
},
"2": {
"id": "17",
"colour": ""
},
"3": {
"id": "18",
"colour": ""
},
"4": {
"id": "19",
"colour": " fill=\"#A90000\""
},
"5": {
"id": "20",
"colour": ""
}
},
"-3": {
"-5": {
"id": "21",
"colour": ""
},
"-4": {
"id": "22",
"colour": ""
},
"-3": {
"id": "23",
"colour": ""
},
"-2": {
"id": "24",
"colour": ""
},
"-1": {
"id": "25",
"colour": ""
},
"1": {
"id": "26",
"colour": ""
},
"2": {
"id": "27",
"colour": ""
},
"3": {
"id": "28",
"colour": ""
},
"4": {
"id": "29",
"colour": " fill=\"#A90000\""
},
"5": {
"id": "30",
"colour": ""
}
},
"-2": {
"-5": {
"id": "31",
"colour": ""
},
"-4": {
"id": "32",
"colour": ""
},
"-3": {
"id": "33",
"colour": ""
},
"-2": {
"id": "34",
"colour": ""
},
"-1": {
"id": "35",
"colour": ""
},
"1": {
"id": "36",
"colour": ""
},
"2": {
"id": "37",
"colour": ""
},
"3": {
"id": "38",
"colour": ""
},
"4": {
"id": "39",
"colour": ""
},
"5": {
"id": "40",
"colour": ""
}
},
"-1": {
"-5": {
"id": "41",
"colour": ""
},
"-4": {
"id": "42",
"colour": ""
},
"-3": {
"id": "43",
"colour": " fill=\"#A90000\""
},
"-2": {
"id": "44",
"colour": ""
},
"-1": {
"id": "45",
"colour": ""
},
"1": {
"id": "46",
"colour": ""
},
"2": {
"id": "47",
"colour": ""
},
"3": {
"id": "48",
"colour": ""
},
"4": {
"id": "49",
"colour": ""
},
"5": {
"id": "50",
"colour": ""
}
},
"1": {
"-5": {
"id": "51",
"colour": " fill=\"#A90000\""
},
"-4": {
"id": "52",
"colour": ""
},
"-3": {
"id": "53",
"colour": ""
},
"-2": {
"id": "54",
"colour": " fill=\"#A90000\""
},
"-1": {
"id": "55",
"colour": ""
},
"1": {
"id": "56",
"colour": ""
},
"2": {
"id": "57",
"colour": ""
},
"3": {
"id": "58",
"colour": ""
},
"4": {
"id": "59",
"colour": ""
},
"5": {
"id": "60",
"colour": ""
}
},
"2": {
"-5": {
"id": "61",
"colour": ""
},
"-4": {
"id": "62",
"colour": ""
},
"-3": {
"id": "63",
"colour": ""
},
"-2": {
"id": "64",
"colour": ""
},
"-1": {
"id": "65",
"colour": ""
},
"1": {
"id": "66",
"colour": ""
},
"2": {
"id": "67",
"colour": ""
},
"3": {
"id": "68",
"colour": ""
},
"4": {
"id": "69",
"colour": ""
},
"5": {
"id": "70",
"colour": ""
}
},
"3": {
"-5": {
"id": "71",
"colour": ""
},
"-4": {
"id": "72",
"colour": " fill=\"#000D81\""
},
"-3": {
"id": "73",
"colour": ""
},
"-2": {
"id": "74",
"colour": ""
},
"-1": {
"id": "75",
"colour": ""
},
"1": {
"id": "76",
"colour": ""
},
"2": {
"id": "77",
"colour": ""
},
"3": {
"id": "78",
"colour": ""
},
"4": {
"id": "79",
"colour": ""
},
"5": {
"id": "80",
"colour": " fill=\"#A90000\""
}
},
"4": {
"-5": {
"id": "81",
"colour": ""
},
"-4": {
"id": "82",
"colour": ""
},
"-3": {
"id": "83",
"colour": ""
},
"-2": {
"id": "84",
"colour": ""
},
"-1": {
"id": "85",
"colour": ""
},
"1": {
"id": "86",
"colour": " fill=\"#A90000\""
},
"2": {
"id": "87",
"colour": ""
},
"3": {
"id": "88",
"colour": ""
},
"4": {
"id": "89",
"colour": ""
},
"5": {
"id": "90",
"colour": ""
}
},
"5": {
"-5": {
"id": "91",
"colour": ""
},
"-4": {
"id": "92",
"colour": ""
},
"-3": {
"id": "93",
"colour": " fill=\"#A90000\""
},
"-2": {
"id": "94",
"colour": ""
},
"-1": {
"id": "95",
"colour": ""
},
"1": {
"id": "96",
"colour": ""
},
"2": {
"id": "97",
"colour": ""
},
"3": {
"id": "98",
"colour": ""
},
"4": {
"id": "99",
"colour": ""
},
"5": {
"id": "100",
"colour": ""
}
}
}
Upvotes: 0
Views: 2023
Reputation: 43884
Ima place this answer cos I think the OP has confused arrays and objects.
This will work:
var t;
$.getJSON('/url', {param: someparam}, function(data){
t = data;
});
The data var represents the stringifyed JSON output and you basically just pass the output to a globally defined var...done.
It will get your JSON out all into one Object. You cannot have an array since minus numbers are not counted as int arrray keys in JS.
Bu this will allow you to do:
$.each(t, function(){
console.log($(this));
});
And get your "row" out.
Or like:
t['-3'];
To understand this difference between arrays and Objects read here: http://www.hunlock.com/blogs/Mastering_Javascript_Arrays
And another link: What is the difference between an array and an object?
Upvotes: 4