Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

The code below is from wunderground weather api, and I'm using javascript to print json data, but how can I print a specific row from json?

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>
<script>
jQuery(document).ready(function($) {
  $.ajax({
        url : "http://api.wunderground.com/api/<apikey>/geolookup/conditions/q/IA/Cedar_Rapids.json",
        dataType : "jsonp",
        success : function(parsed_json) {
              var location = parsed_json['location']['city'];
              var temp_f = parsed_json['current_observation']['temp_f'];
              alert("Current temperature in " + location + " is: " + temp_f);
        }
  });
});
</script>

For example in ['location'], to get the first result because it can be array ['location'][0] something like this

share|improve this question
What array are you referring to? If you look at the response, under "location", there is "nearby_weather_stations", under that is "airport", and under that is "stations". That is one of the arrays I found. Other than that, "pws" is next to "airport". "location" is not a collection - it's a single item. – Ian Nov 5 '12 at 17:10
location is a single object. – Sheikh Heera Nov 5 '12 at 17:12
Can you provide any examples of location being an array? – invertedSpear Nov 5 '12 at 17:17
ok thanks for the reply, it was just an example im using googleapi and there are collection of rows i just wanted to know how to access them imagine location is a collection how can first data be accessed from there. This is the link im using maps.googleapis.com/maps/api/place/textsearch/… – user1800426 Nov 5 '12 at 17:18
1  
Unless I misunderstand your question, you answered it in your post. For example in ['location'] to get the first result because it can be array ['location'][0] If it is an array, then access it with array notation. – Chad Nov 5 '12 at 17:21
show 4 more comments

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.