0

Using the Parse PHP API - I am calling a query to return an object from the table which is working great. Upon var_dump($parseobjecthere) I receive a nice hierarchical output of the object which I'd like to convert to an associative array. Does anybody have any suggestions for how this may happen - as I can't seem to locate anything relevant in the documentation.

Thanks in advance,

Sean

Sean Leach
  • 49
  • 6
  • This question (and answers) may help you out -> [**Convert var_dump of array back to array variable**](http://stackoverflow.com/questions/3531857/convert-var-dump-of-array-back-to-array-variable) there is as far as I know no native var_dump => array / object method in PHP. – davidkonrad Oct 08 '14 at 11:28

2 Answers2

0

I just checked their docs and they say they return JSON so perhaps all you need to do is :

$array = json_decode($parseobjecthere, 1);

print_r($array);
myte
  • 887
  • 7
  • 10
  • Unfortunately this didn't work - `json_decode() expects parameter 1 to be string, object given` I'll attempt to cast to a string and see how it goes! Thanks for the direction. Could you advise where in the docs you found this? – Sean Leach Oct 08 '14 at 11:26
  • oops i didnt read far enough into their API ( i just skimmed the first part) ... it looks like these objects just store key-value pairs – myte Oct 08 '14 at 11:35
  • also i was looking at their REST API (which says it returns JSON) and not the PHP API As you said you were using. – myte Oct 08 '14 at 11:43
0

I'm not sure it's a full answer - so I'll leave the question open to see if somebody with better skill than myself can give a more appropriate answer.

In my solution - I only needed to extract the serverData element which was protected. Upon casting the object to an array - the key *serverData was extracted using the null character format - (array) $parseObject["\0*\0serverData"]

This can then be iterated through as a standard array.

Thanks for the input from everybody. It seems like there must be a better way around doing it so the function is still marked with //TODO - Rejig this!

Sean Leach
  • 49
  • 6