When I load the page, I try to display the contents of the .json file, but the string [object Object][object Object][object Object][object Object][object Object] falls into the output. What am I doing wrong?

 <div id="airport-list"></div> <script> $(function(){ $.getJSON('/json/airports.json', function(data) { $.each(data, function(i, field){ $('#airport-list').append(field + '' ); }); }); }); </script> 

You need to pull out the value of the ru field in the name_translations field in a row that looks like this:

 { "code":"SVO", "name":"Sheremetyevo International", "coordinates":{"lon":37.416573,"lat":55.966324}, "time_zone":"Europe/Moscow", "name_translations":{ "en":"Sheremetyevo International", "de":"Moskau-Scheremetjewo", "zh-CN":"谢列梅捷沃机场", "ru":"Шереметьево", "tr":"Şeremetyevo Uluslararası Havalimanı", "it":"Sheremetyevo", "fr":"Sheremetyevo", "es":"Sheremetyevo", "th":"สนามบินนานาชาติเชเรเมเตียโว" }, "country_code":"RU", "city_code":"MOW" } 
  • what is field ? give an example of the returned data - Igor
  • @Igor yes no idea. Took an example here . I need to pull out the ru field value in the name_translations field. Sample object added to the post. - JamesJGoodwin

1 answer 1

In the example following the link from your comment, the iteration is performed on the object properties, the values ​​of these properties are passed to the anonymous handler each . In the code of the question, data is an array, and field - objects are elements of an array.

http://api.jquery.com/jquery.each/

  $('#airport-list').append(field["name_translations"]["ru"] + '' );