If your file.php
script returns the appropriate data type for it's response, then the data
argument will already contained parsed JSON (e.g. in live javascript variable form).
If you don't like the form that the data is in and you want to convert it to an array from something else, you would have to show us what format it's in so we can advise on code to convert it to some other form.
If you just want to store the data in a variable so you can use it elsewhere, then you can do that by storing it in a global variable:
var fileData;
jQuery.getJSON("file.php", function(data) {
fileData = data;
// call any functions here that might want to process this data as soon as it's ready
});
The data is now in a global variable named fileData that you can use anywhere on your page. Keep in mind that a getJSON call is asychronous so it might take a little while to complete and the data won't be available in your variable until the getJSON callback is called.
If you were calling this multiple times and wanted to collect each response, you could collect them into an array like this:
var fileData = []; // declare empty array
jQuery.getJSON("file.php", function(data) {
fileData.push(data); // add onto the end of the array
// call any functions here that might want to process this data as soon as it's ready
});