It seems that the returned data is an object rather than an array..I’m not sure wether this is due to your json encoding or not tho. When checking the documentation it’s clearly an array and not an object..
If this is what you get back using my code it does seem to run through the foreach since you do get something in “gallery” the issue seems to be that it does not add constrain which it should.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users