duanbi8529 2016-01-08 17:20
浏览 6
已采纳

我无法在PHP中获取JSON输出

I got the following response output from curl request.

Array
(
    [code] => 200
    [message] => Message history obtained successfully.
    [data] => Array
        (
            [0] => Array
                (
                    [id] => 3390257
                    [aggregator_id] => 25
                    [user_id] => 184279092
                    [message_id] => 7784285
                    [ext_message_id] => 152127f68b2000031bf6584fa8494a7b
                    [send_date] => 2016-01-05 09:54:17
                    [dest_address] => 8476099160
                    [dest_country] => 1
                    [dest_type] => 1
                    [source_address] => 8
                    [source_country] => 1
                    [source_type] => 2
                    [message] => Heres  how others are earning up to an extra $300/day simply by using their phone or working from home Click Here now: http://bit.ly/1PIiVZl
                    [transaction_id] =>
                    [message_status] => 14
                    [message_schedule_id] => 59335
                    [last_modified_date] => 2016-01-05 09:54:52
                    [last_modified_user_id] => 184279092
                    [keyword_id] => 1459
                )

            [1] => Array
                (
                    [id] => 3390261
                    [aggregator_id] => 25
                    [user_id] => 184279092
                    [message_id] => 7784289
                    [ext_message_id] => 152127f6c36000171df5874efba398b4
                    [send_date] => 2016-01-05 09:54:17
                    [dest_address] => 6188892860
                    [dest_country] => 1
                    [dest_type] => 1
                    [source_address] => 8
                    [source_country] => 1
                    [source_type] => 2
                    [message] => Heres  how others are earning up to an extra $300/day simply by using their phone or working from home Click Here now: http://bit.ly/1PIiVZl
                    [transaction_id] =>
                    [message_status] => 14
                    [message_schedule_id] => 59335
                    [last_modified_date] => 2016-01-05 09:54:52
                    [last_modified_user_id] => 184279092
                    [keyword_id] => 1459
                )

            [2] => Array
                (
                    [id] => 3390265
                    [aggregator_id] => 25
                    [user_id] => 184279092
                    [message_id] => 7784293
                    [ext_message_id] => 152127f65dd000031bf6584fa84949af
                    [send_date] => 2016-01-05 09:54:17
                    [dest_address] => 2032415751
                    [dest_country] => 1
                    [dest_type] => 1
                    [source_address] => 8
                    [source_country] => 1
                    [source_type] => 2
                    [message] => Heres  how others are earning up to an extra $300/day simply by using their phone or working from home Click Here now: http://bit.ly/1PIiVZl
                    [transaction_id] =>
                    [message_status] => 14
                    [message_schedule_id] => 59335
                    [last_modified_date] => 2016-01-05 09:54:52
                    [last_modified_user_id] => 184279092
                    [keyword_id] => 1459
                )

            [3] => Array
                (
                    [id] => 3390270
                    [aggregator_id] => 25
                    [user_id] => 184279092
                    [message_id] => 7784298
                    [ext_message_id] => 152127f6a2a0001a8d8e4ef0eebbbe5d
                    [send_date] => 2016-01-05 09:54:17
                    [dest_address] => 3106193605
                    [dest_country] => 1
                    [dest_type] => 1
                    [source_address] => 8
                    [source_country] => 1
                    [source_type] => 2
                    [message] => Heres  how others are earning up to an extra $300/day simply by using their phone or working from home Click Here now: http://bit.ly/1PIiVZl
                    [transaction_id] =>
                    [message_status] => 14
                    [message_schedule_id] => 59335
                    [last_modified_date] => 2016-01-05 09:54:52
                    [last_modified_user_id] => 184279092
                    [keyword_id] => 1459
                )

        )

)

Now I want to get the array value like $keyword_id = 1459 But I can't access the array.

  • 写回答

2条回答 默认 最新

  • dourong9253 2016-01-08 17:34
    关注

    Assuming this response is stored in a variable called $response, here are some examples of accessing array elements...

    $response['data'][0]['id']            // 3390257 (id of 1st data element)
    $response['data'][1]['dest_address']  // 6188892860 (dest_address of 2nd data element)
    $response['data'][3]['keyword_id']    // 1459 (keyword_id of 4th data element)
    

    You could also iterate over the data elements and print the ids as follows...

    foreach ($response['data'] as $i => $element) {
        echo "The id of element " . $i . " is " . $element['id'] . "
    ";
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度