Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8773837
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T18:24:24+00:00 2026-06-13T18:24:24+00:00

I am new to PHP and not very clear how to parse JSON with

  • 0

I am new to PHP and not very clear how to parse JSON with PHP. This is the JSON i am getting from a third party

{ "data": 
  { "current_condition": 
   [ 
      {"cloudcover": "0", "humidity": "13", "observation_time": "05:47 AM", "precipMM": "0.0", 
      "pressure": "1016", "temp_C": "20", "temp_F": "69", 
      "visibility": "10", "weatherCode": "113",  
      "weatherDesc": [ {"value": "Sunny" } ],  
      "weatherIconUrl": [ {"value": "http:\/\/www.worldweatheronline.com\/images\/wsymbols01_png_64\/wsymbol_0001_sunny.png" } ], 
     " winddir16Point": "SW", "winddirDegree": "218", "windspeedKmph": "12", "windspeedMiles": "7" 
     } 
   ],
   "request": [ 
            {"query": "Lat 32.12 and Lon 76.53", "type": "LatLon" } 
      ],  
   "weather": [ 
          {
            "date": "2012-11-04", "precipMM": "0.0", "tempMaxC": "20", "tempMaxF": "69", "tempMinC": "1", "tempMinF": "34", 
            "weatherCode": "113",  "weatherDesc": [ {"value": "Sunny" } ],  
            "weatherIconUrl": [ {"value": "http:\/\/www.worldweatheronline.com\/images\/wsymbols01_png_64\/wsymbol_0001_sunny.png" } ], 
            "winddir16Point": "SW", "winddirDegree": "218", "winddirection": "SW", "windspeedKmph": "12", "windspeedMiles": "8" 
           }, 
          {
           "date": "2012-11-05", "precipMM": "0.0", "tempMaxC": "20", "tempMaxF": "67", "tempMinC": "4", "tempMinF": "39", 
           "weatherCode": "113", "weatherDesc": [ {"value": "Sunny" } ], 
           "weatherIconUrl": [ {"value": "http:\/\/www.worldweatheronline.com\/images\/wsymbols01_png_64\/wsymbol_0001_sunny.png" } ], 
           "winddir16Point": "SSW", "winddirDegree": "210", "winddirection": "SSW", "windspeedKmph": "12", "windspeedMiles": "7" 
           } 
          ] 
        }
     }

I am getting this weather information as JSON data which includes following information

  1. Current information
  2. Weather information for next 2 days

I do not want all information but only specific one like

current_condition
       temp_C
       temp_F
       weatherDesc

Than i want some data from the weather information provides for next 2 days

  1. date
  2. tempMaxC
  3. tempMinC
  4. weatherIconUrl
  5. windspeedKmph

i tried this code in PHP

$jsonIterator = new RecursiveIteratorIterator(
    new RecursiveArrayIterator(json_decode($weather, TRUE)),
    RecursiveIteratorIterator::SELF_FIRST);

which seems to give me the JSON decoded data in the array format but i got confused in how to fetch those specific values from the PHP data. I can iterate over the Data

foreach ($jsonIterator as $key => $value) {
    if(is_array($value)) {
        foreach ($value as $key => $value) {
    }

    } else {
       // echo "$key\n";
    }

but not sure how to fetch values as described above.Any help or pointer for resources will really be helpful

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T18:24:25+00:00Added an answer on June 13, 2026 at 6:24 pm

    Why don’t you just use json_decode and then process the resulting object?

    Example: http://codepad.org/ciw3ogAu

    I used ob_get_content() because I don’t want to mess up with the escape sequences, but the focus is on this line:

    $result = json_decode($my_json_string);
    

    It’s not difficult to obtain information. For example if you want the current temperature in Celsius:

    echo $result->data->current_condition[0]->temp_C;
    

    You can get an array of the future two days (http://codepad.org/bhOcd3eT):

    $weatherarray = $result->data->weather; // An array with two elements
    

    You use $result->xxx instead of $result["xxx"] because json_decode will create objects for objects. You can change it to be arrays by calling json_decode($my_json_string, true), then you access members using the following way:

    echo $result["data"]["current_condition"][0]["temp_C"];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm very new in php. So i realize from my first steps is this
I'm not sure why this SQL query is not working. I'm new to SQL/PHP
This is working fine in core php, but not in magento. $party_payment = new
New to php Sessions here. My stored user data is pretty minor and not
I am not very skilled in php, but I believe something in this section
Hey I am very new to Web Programming. I have been learning PHP from
I'm new to php world (actually not so much, but pretty much). I make
I'm relatively new to php development but not to web development in general. I
I'm not exactly new to PHP but I haven't used MySQL that much, so
I am not new to Wordpress, but new to PHP. I have managed to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.