将嵌套的xAPI JSON输出转换为PHP数组

时间:2018-02-24 09:41:46

标签: php json associative-array box-api

Array
(
    [0] => TinCan\Statement Object
        (
            [id:protected] => 0a53e06c-64a7-4902-930e-993bb228cd49
            [stored:protected] => 2018-02-24T04:21:22.456Z
            [authority:protected] => TinCan\Agent Object
                (
                    [objectType:protected] => Agent
                    [name:protected] => sabarish
                    [mbox:protected] => 
                    [mbox_sha1sum:protected] => 
                    [openid:protected] => 
                    [account:protected] => TinCan\AgentAccount Object
                        (
                            [name:protected] => 248a06f20aa62f
                            [homePage:protected] => https://sandbox.watershedlrs.com
                        )
            )

        [version:protected] => 1.0.0
        [attachments:protected] => Array
            (
            )

        [actor:protected] => TinCan\Agent Object
            (
                [objectType:protected] => Agent
                [name:protected] => Akshaya Manikandan
                [mbox:protected] => mailto:aksh.m14@gmail.com
                [mbox_sha1sum:protected] => 
                [openid:protected] => 
                [account:protected] => 
            )

        [verb:protected] => TinCan\Verb Object
            (
                [id:protected] => http://adlnet.gov/expapi/verbs/skipped
                [display:protected] => TinCan\LanguageMap Object
                    (
                        [_map:protected] => Array
                            (
                                [en] => skipped
                            )

                    )

            )

        [target:protected] => TinCan\Activity Object
            (
                [objectType:TinCan\Activity:private] => Activity
                [id:protected] => https://app.acuizen.com/populate_form/965/1573/4690
                [definition:protected] => 
            )

        [result:protected] => 
        [context:protected] => TinCan\Context Object
            (
                [registration:protected] => 
                [instructor:protected] => 
                [team:protected] => 
                [contextActivities:protected] => TinCan\ContextActivities Object
                    (
                        [category:protected] => Array
                            (
                                [0] => TinCan\Activity Object
                                    (
                                        [objectType:TinCan\Activity:private] => Activity
                                        [id:protected] => http://acuizen.com/ActivitySkipped
                                        [definition:protected] => TinCan\ActivityDefinition Object
                                            (
                                                [type:protected] => http://id.tincanapi.com/activitytype/Assignment
                                                [name:protected] => TinCan\LanguageMap Object
                                                    (
                                                        [_map:protected] => Array
                                                            (
                                                            )

                                                    )

                                                [description:protected] => TinCan\LanguageMap Object
                                                    (
                                                        [_map:protected] => Array
                                                            (
                                                            )

                                                    )

                                                [moreInfo:protected] => 
                                                [extensions:protected] => TinCan\Extensions Object
                                                    (
                                                        [_map:protected] => Array
                                                            (
                                                            )

                                                    )

                                                [interactionType:protected] => 
                                                [correctResponsesPattern:protected] => 
                                                [choices:protected] => 
                                                [scale:protected] => 
                                                [source:protected] => 
                                                [target:protected] => 
                                                [steps:protected] => 
                                            )

                                    )

                            )

                        [parent:protected] => Array
                            (
                            )

                        [grouping:protected] => Array
                            (
                            )

                        [other:protected] => Array
                            (
                            )

                    )

                [revision:protected] => 
                [platform:protected] => 
                [language:protected] => 
                [statement:protected] => 
                [extensions:protected] => TinCan\Extensions Object
                    (
                        [_map:protected] => Array
                            (
                            )

                    )

            )

        [timestamp:protected] => 2018-02-24T04:21:22.456Z
    )

... + 100更喜欢这些。

运行我的php代码后我得到了这个输出来从LRS中检索所有信息。如何将其更改为PHP ARRAY?

2 个答案:

答案 0 :(得分:0)

如果没有您的PHP代码,我只能假设您使用的是json_decode($response)而不是json_decode($response, true)。此函数中的第二个参数决定是否按原样或简单数组解码为类。

答案 1 :(得分:0)

您需要学习如何使用他们的API文档,没有简单的"获取所有数据"我可以看到,因为所有内容都包含在具有私有/受保护属性的类中....

使用您提供的示例,以下是如何获取演员的示例"

$Statements = getAllActivity()->content->getStatements();

foreach( $Statements as $Statement )
{
  print_r( $Statement->getActor() );
  print_r( $Statement->getActor()->getName() );
  print_r( $Statement->getActor()->getMbox() );
}

查看脚本\src\StatementBase.php,这是我找到getAcator()方法

的地方