i’ve tried a few different json methods (stringify, toJSON, and probably some totally irrelevant others out of desperation) but can’t seem to figure out how to stringify this so i can pass it to a php script. i am able to create a two dimensional array that which could be represented something like this:
array(
'image'=>array(
0=>'hello.jpeg',
1=>'goodbye.jpeg',
2=>'etc.jpeg'),
'resume'=>array(
0=>'resume.doc'),
'reel'=>array(
0=>'reel.mov')
)
the array looks okay when i print it to console using this dump function. i tried figuring out how to get this to work with objects because i thought i read something that said objects were already JSON friendly, but since i’m not super familiar with javascript i was pretty much floundering about.
edit: some more details… the declaration of my array (when i had it working) was something like this, although i may have messed up:
var fileArray = [];
fileArray['image'] = [];
fileArray['resume'] = [];
fileArray['reel'] = [];
var type;
var name;
var divs = $("#upload-container").children('div');
$.each(divs, function() {
type = $(this).attr('id');
name = $(this).html();
fileArray[type].push(name);
});
The object for that array structure might look like this in JavaScript:
So now you’ve got an array of three objects, each of which contains a property (image, resume, reel) that is another array of objects with basically key:value pairs (
'0':'hello.jpeg'). Maybe you could simplify it by not bothering to use the indexes:Then you can use
JSON.stringify(objects)to pass to your PHP action.