HI I have a tricky and urgent question which has made me almost pull my hair out for a day or two. Would so much appreciate some help on it!
This is the code I am working on and that I need some help with:
Background: From an api call I get a long and tedious php array. I have a function that strips this array down to a minimum and after that, saves it as json and puts it in a file on a server.
Among other thing, it stores the object "Occations". My code (I am making an app using this data) works fine, as long as there is only ONE occation.
However, sometimes "occations" consists of an array holding numerous objects. When so, several fields in the app are blank.
I want to be able to make a check = if "occations" holds more than one occation = loop through them all and pull the data I need from it.
This is a sample of the original data, when it holds just one occation:
"Occasions":{ "OccasionObject":{ "Id":19926396, "AttributeId":111, "ProductId":603298, "OrganizationId":1045, "StartDate":"2014-12-10T00:00:00", "EndDate":"2014-12-11T00:00:00", "StartTime":"0001-01-01T19:00:00", "EndTime":"0001-01-01T19:00:00", "ValidDays":"Wednesday Thursday", "ArenaId":55, "ArenaName":"Rum", "EntryTime":"0001-01-01T00:00:00" } },And this is a sample of when it holds many:
"Occasions":{ "OccasionObject":[ { "Id":19553154, "AttributeId":111, "ProductId":685680, "OrganizationId":1045, "StartDate":"2014-09-21T00:00:00", "EndDate":"2014-10-30T00:00:00", "StartTime":"0001-01-01T12:00:00", "EndTime":"0001-01-01T17:00:00", "ValidDays":"Tuesday Wednesday Thursday Friday", "ArenaId":55, "ArenaName":"Rum", "EntryTime":"0001-01-01T00:00:00" }, { "Id":19553155, "AttributeId":111, "ProductId":685680, "OrganizationId":1045, "StartDate":"2014-10-31T00:00:00", "EndDate":"2014-10-31T00:00:00", "StartTime":"0001-01-01T12:00:00", "EndTime":"0001-01-01T16:00:00", "ValidDays":"Friday", "ArenaId":555, "ArenaName":"Rum", "EntryTime":"0001-01-01T00:00:00" } ]So. in the case of when only one occation, this is part of the final json (looking the way I want it to):
{ "Id": 11, "Name": "Moviename", "Image": { "Width": 214, "Height": 317 }, "Phone": "05504-345", "Price": "4 biljons", "LongText": "Yes a long text", "ShortText": "Yes, short", "StartDate": "2014-11-12T00:00:00", "EndDate": "2014-11-13T00:00:00", "StartTime": "0001-01-01T19:00:00", "ValidDays": "Wednesday Thursday", "ArenaId": 55, "ArenaName": "Rum" },However when several occations, the fields StartDate, EndDate, StartTime, ValidDays, ArenaId, ArenaName all are empty.
So I need to alter my coding (link in the top) so that it accepts both one and several occations. I can not figure out how to do it!
Any hints? Please?