Is there a place that has examples and instructions on how to do Json requests to a url, and then parse the responses?
I just can’t wrap my head around it.
Is there a place that has examples and instructions on how to do Json requests to a url, and then parse the responses?
I just can’t wrap my head around it.
Sorry for the screenshot but I’m using the iPad today and couldn’t save this from WebCore. I simply build the api_url as a variable (this one has two flavors a test sandbox and the real thing), then do a get request using the url. $response will give you the whole JSON response which I had to reverse engineer for this API because the vendor docs were out of date.
Please pardon the messy code I am still playing around.
Thanks. I will play with this and ask questions based on what I find. Just getting started on this stuff
I have been able to make the request to weather underground and able to set the response to a variable. Now how do I parse out the info that was responded. Here is what the response gave me. What I am trying to do is basically pulling weather info from a location other than my home hub location.
Sorry, haven’t had a chance to look at this yet. Although if you tear through a couple of the example pistons that will help.
Ok.
Still a little unclear on what you want to do next. However if what you want is a specific value from that JSON $response you refer to it by name. For example $response.features.forecast[0] should return a value of 1.
Each “word” followed by a colon is a label for a field. Brackets indicate an array.
If you take your url and paste it into a browser you should get a formatted version of the JSON output. That may help you better understand the structure.
Hope this helps.
Oddly enough it may be $response.response.features.forecast[0]
Here is a partial formatted response for current conditions from their website.
{
“response”: {
“version”: “0.1”,
“termsofService”: “http://www.wunderground.com/weather/api/d/terms.html”,
“features”: {
“conditions”: 1
}
},
“current_observation”: {
“image”: {
“url”: “http://icons-ak.wxug.com/graphics/wu2/logo_130x80.png”,
“title”: “Weather Underground”,
“link”: “http://www.wunderground.com”
},
“display_location”: {
“full”: “San Francisco, CA”,
“city”: “San Francisco”,
“state”: “CA”,
“state_name”: “California”,
“country”: “US”,
“country_iso3166”: “US”,
“zip”: “94101”,
Thanks for the help thus far. Will play with after work. What I am trying to do is get weather info for different cities other than my hub location. This way I could get New York weather, hub location weather, or Los Angeles weather depending on the api call. If I use the $weather function, it is based on what location my hub is set up too.
Thank you! What I needed was $ response.current_conditions.wind_string and it gives me what I need. Thanks again