I make a request to the API here , in return I get an xml-string, then on the server side (PHP) I convert the string to json. After that, I can apply for this json string with an ajax request, which I tried to do, but I got this line:
{ "offer":{ "@attributes":{ "airline":"Россия", "airline_code":"FV", "title":"Из Санкт-Петербурга в Ростов-на-Дону от 5000 рублей! Специальное предложение от авиакомпании Россия", "id":"21888", "href":"https://www.aviasales.ru/offers/iz-sankt-peterburga-v-rostov-na-donu-ot-5000-rublei-spetsialnoe-predlozhenie-ot-aviakompanii-rossiya", "sale_date_begin":"1475625600", "sale_date_end":"1512086400", "flight_date_begin":"1475625600", "flight_date_end":"1490400000", "link":"https://hydra.aviasales.ru/adaptors/special_offer?iata=FV&utm_source=www&lo…Fnews%2Fsale_of_tickets_for_flights_from_st_petersburg_to_rostov_on_don%2F" }, "description":{ }, "conditions":"<ul><li>Цены на авиабилеты указаны с учетом топливных, аэропортовых и государственных сборов.</li><li>Количество авиабилетов на каждом рейсе по данному тарифу ограничено.</li><li>Полные условия продажи авиабилетов на сайте авиакомпании.</li></ul>", "route":[ { "@attributes":{ "from_iata":"LED", "to_iata":"ROV", "from_name":"Санкт-Петербург", "to_name":"Ростов-на-Дону", "class":"эконом", "oneway_price":"от 5000 рублей", "roundtrip_price":"" } }, { "@attributes":{ "from_iata":"LED", "to_iata":"ROV", "from_name":"Санкт-Петербург", "to_name":"Ростов-на-Дону", "class":"эконом", "oneway_price":"", "roundtrip_price":"от 10000 рублей" } } ] } } There may be several such offer , but the question is how do I access the fields with the name @attributes ? By the way, I process the output using for in .
offera few. Why can't you access the xml file? - Yuriobj.offer['@attributes'].airlineAirline - Orange_shadowfor..in? unclear ......for (var test in json.offer) { console.log(json.offer[test]); }for (var test in json.offer) { console.log(json.offer[test]); }works quietly ......... and jquery has api.jquery.com/jQuery.parseXML - Alexey Shimansky