how to iterate over JSON property not knowing if it's array or not?

后端 未结 3 424
既然无缘
既然无缘 2021-01-25 20:28

I have this problem where an API responds to me with DEPARTURESEGMENT sometimes containing only one object, and sometimes containing an array of objects. Depending on which case

3条回答
  •  佛祖请我去吃肉
    2021-01-25 20:51

    How about checking whether it's an array or not with is_array? I made a simple example of it's usage here - http://codepad.org/WNjbIPZF

提交回复
热议问题