将SimpleXML转换为JSON PHP

时间:2013-10-04 09:41:43

标签: php xml json

我正在使用Bigbluebutton的PHP API,我希望得到所有会议。在调用显示会议的方法时,我得到了这个输出:

Array (

[returncode] => SimpleXMLElement Object
    (
        [0] => SUCCESS
    )

[messageKey] => SimpleXMLElement Object
    (
    )

[message] => SimpleXMLElement Object
    (
    )

[0] => Array
    (
        [meetingId] => SimpleXMLElement Object
            (
                [0] => as's meeting
            )

        [meetingName] => SimpleXMLElement Object
            (
                [0] => as's meeting
            )

        [createTime] => SimpleXMLElement Object
            (
                [0] => 1380878550574
            )

        [attendeePw] => SimpleXMLElement Object
            (
                [0] => ap
            )

        [moderatorPw] => SimpleXMLElement Object
            (
                [0] => mp
            )

        [hasBeenForciblyEnded] => SimpleXMLElement Object
            (
                [0] => false
            )

        [running] => SimpleXMLElement Object
            (
                [0] => false
            )

    )

[1] => Array
    (
        [meetingId] => SimpleXMLElement Object
            (
                [0] => XYZ's meeting
            )

        [meetingName] => SimpleXMLElement Object
            (
                [0] => XYZ's meeting
            )

        [createTime] => SimpleXMLElement Object
            (
                [0] => 1380879253000
            )

        [attendeePw] => SimpleXMLElement Object
            (
                [0] => ap
            )

        [moderatorPw] => SimpleXMLElement Object
            (
                [0] => mp
            )

        [hasBeenForciblyEnded] => SimpleXMLElement Object
            (
                [0] => false
            )

        [running] => SimpleXMLElement Object
            (
                [0] => true
            )

    )

)

如何将这个simplexml转为top json?

1 个答案:

答案 0 :(得分:5)

您可以使用json_encode。 http://php.net/manual/en/function.json-encode.php

json_encode($array)