Hướng dẫn check empty json php
I'm reading JSON data with PHP and that data contains empty objects (like
YakovL 6,91012 gold badges57 silver badges88 bronze badges asked Sep 7, 2009 at 13:28
1 How many objects are you unserializing? Unless I'd suggest using the the
This decodes JSON
objects as plain old PHP arrays instead of as answered Sep 7, 2009 at 14:07
1
You could cast it to an array (unfortunately you can't do this within a call to
Or cast to an array and
answered Sep 7, 2009 at 13:37
GregGreg 310k53 gold badges366 silver badges328 bronze badges 4 Try without using
On PHP docs we can read the note:
Which means when using answered Mar 4, 2015 at 22:18
kenorbkenorb 144k76 gold badges655 silver badges710 bronze badges I had to tell if an object was empty or not, but I also had to ignore private and protected properties, so I made this little function with which you can do this.
answered Jul 27, 2011 at 13:06
ParziphalParziphal 5,5523 gold badges35 silver badges34 bronze badges I am not sure if this is more or less effective than casting to an array but I would guess more. You could just start to loop the object and as soon as you find something you have an answer and stop looping.
answered Sep 11, 2014 at 15:03
AdamAdam 6,5243 gold badges40 silver badges60 bronze badges |