php simpleXMLElement to array: null value

后端 未结 3 1780
南方客
南方客 2021-02-14 13:49

I\'ve got following XML:


    123
    
    ACTIVE

         


        
3条回答
  •  星月不相逢
    2021-02-14 14:14

    I cannot add a comment, but I think this will work for you, it should be faster then a regex or a loop:

    //after you json_encode, before you decode
    $str = str_replace(':[]',':null',json_encode($array));
    

    An empty array in JSON is represented by "[]". Sometimes the arrays are parsed as objects, in that case (or as a fallback) you can replace ":{}" too.

提交回复
热议问题