Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder darksecu's Avatar
    Join Date
    Dec 2011
    Location
    India
    Posts
    146
    Thanks
    15
    Thanked 2 Times in 2 Posts

    Help Reading An API Response [In Array]

    Hey Everyone,
    how do we read a API response statement coded below in PHP.
    Code:
    {"vehicleStatuslist":[{"Veh_reg":"HR63CXXXX", "datetime":"08-12-17 17:31", "Latitude":"28.683427811","Longitude":"77.013397217" ,"Speed":"0 km/h"}]}
    please assist.
    I am further planning to get the location name using latitude and longitude using google map, would be great if you can share the working snippet of the same.
    I am not a programming professional, apologies for being too basic here !
    When You Begin To Practice,That's The Time You Begin To Learn New Things.

  2. #2
    Master Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Location
    Behind the Wall
    Posts
    5,860
    Thanks
    26
    Thanked 609 Times in 602 Posts
    The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
    André Behrens, NY Times Software Developer

  3. #3
    Regular Coder darksecu's Avatar
    Join Date
    Dec 2011
    Location
    India
    Posts
    146
    Thanks
    15
    Thanked 2 Times in 2 Posts
    Hello, Thanks a lot sir for jumping in here!
    I am noob, unable to decode the array properly.

    PHP Code:
    $contents file_get_contents($url); 
    $contents utf8_encode($contents); 
    $results json_decode($contentstrue); 
    foreach(
    $results as $show) {
    echo 
    $show[0][datetime];

    how can i extract data without using foreach statement, direct data extraction from $results itself ?
    When You Begin To Practice,That's The Time You Begin To Learn New Things.

  4. #4
    Supreme Master coder!
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    10,396
    Thanks
    10
    Thanked 1,191 Times in 1,181 Posts
    PHP Code:
    <?php
    $info
    ='
    {"vehicleStatuslist":[{"Veh_reg":"HR63CXXXX", "datetime":"08-12-17 17:31", "Latitude":"28.683427811","Longitude":"77.013397217" ,"Speed":"0 km/h"}]}
    '
    ;
    $latitude "not defined";
    $longitude "not defined";
    $json_array json_decode($infotrue);
    foreach(
    $json_array as $key => $arrays){
        
    //echo $key . "<br />";
        
    foreach($arrays as $array){
            foreach(
    $array as $key => $value){
                if(
    $key == "Latitude"){
                
    $latitude $value;
                }
                if(
    $key == "Longitude"){
                
    $longitude $value;
                }
                
    //echo $key . " => " . $value . "<br />";
            
    }
        }
        echo 
    "<br />";
    }

    echo 
    "<a href='http://maps.google.com/maps?q=$latitude,$longitude&iwloc=A&hl=en&z=13' target='_blank'>Show Me on Google Map</a>";

    ?>
    Last edited by mlseim; Dec 8th, 2017 at 06:43 PM.


 

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •