0

my json decode script throwing error i.e. Error : DATA FETCH

My code:

<?php
$api_url = '{"msg":"SUCCESS","msg_text":"DATA FETCH","data":[{"sn":1,"mob_no":"9602858989","date":"06-May-2015","time":"12:02:33 PM"},{"sn":2,"mob_no":"7795055128","date":"06-May-2015","time":"12:29:44 PM"}]}';

$output = file_get_contents($api_url);
if($output=="")
{
    echo "No output received";
}
else
{
    $arr_output = json_decode($output, true);
    if(isset($arr_output['msg']))
    {
        $msg = $arr_output['msg'];
        $msg_text = $arr_output['msg_text'];

        if($msg == "success")
        {
            if(isset($arr_output['data']))
            {
                $arr_data = $arr_output['data'];

                // above array will contain your data
                print_r($arr_data);
            }
            else
            {
                echo "Json data not set !!";
            }
        }
        else
        {   
            echo "Error : ".$msg_text;
        }
    }
    else
    {
        echo "Output not set !!";
    }
}
?>
2
Contributors
2
Replies
6
Views
2 Years
Discussion Span
Last Post by blueguy777
0
if($msg == "success")

That's case sensitive, and should be:

if ($msg == "SUCCESS")

or:

if (strtolower($msg) == "success")
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.