无法解码json数组 - php

时间:2015-05-28 17:03:23

标签: php json

我有一个php页面,给我一个像这样的json:

{
    "Readings": [
        {
            "MONE_ID": "6",
            "HOTEL_ID": "2",
            "READING_NAME": "head",
            "CURRENT_READING": null,
            "LAST_READING": "12234"
        },
        {
            "MONE_ID": "7",
            "HOTEL_ID": "2",
            "READING_NAME": "ginun",
            "CURRENT_READING": null,
            "LAST_READING": "5444"
        },
        {
            "MONE_ID": "8",
            "HOTEL_ID": "2",
            "READING_NAME": "fire",
            "CURRENT_READING": null,
            "LAST_READING": "6567"
        }
    ]
}

我想从其他php文件发帖来获取json,我想解码它,但我不明白为什么它不顺利。

<?php 

$postdata = http_build_query(
    array(
        'HOTEL_ID' => '2'
    )
);

$opts = array('http' =>
    array(
        'method'  => 'POST',
        'header'  => 'Content-type: application/x-www-form-urlencoded',
        'content' => $postdata
    )
);

$context  = stream_context_create($opts);

$json = file_get_contents('http://www.hotelsmaintenanceservices.com/getDailyReadings.php', false, $context);

$parsed_json = json_decode($json,true);

foreach ($parsed_json ['Readings'] as $reading) 
    {
            $mone_id=$reading['MONE_ID'];
            echo $mone_id; 
        }
?>

有人能说我错了吗?

0 个答案:

没有答案