There is such a JSON response:

{"response": [{"aid":432696864, "owner_id":11111111, "artist":"Ciara", "title":"Paint It Black ( Movie version by Johnny L. ) OST Последний охотник на ведьм.", "duration":190, "url":"https:\/\/psv4.vk.me\/c611329\/u78009459\/audios\/2214a1d193fc.mp3?extra=sn5CXmyOD9TxSI2adKZgrqFZB6hwCVJHMdRJhqlmALnZa1z45HUI989V295mE17bMgK8MUkOvy260V0x9gjDMpXkDcpxkwvaswo68yM5ggomVg", "genre":18} 

you need to pull separately into the variable fields artist , title , url , how to do it correctly

  • 2
    if the answer is received as a string, then call var o = JSON.parse(строка); and get artist as alert(o.response[0].artist); - Stack
  • If you are given an exhaustive answer, mark it as correct (a daw opposite the selected answer). - Nicolas Chabanovsky

1 answer 1

run the code and click on the label, get the value of the url

  $(function() { var data = { "response": [{ "aid": 432696864, "owner_id": 11111111, "artist": "Ciara", "title": "Paint It Black ( Movie version by Johnny L. ) OST Последний охотник на ведьм.", "duration": 190, "url": "https://psv4.vk.me/c611329/u78009459/audios/2214a1d193fc.mp3?extra=sn5CXmyOD9TxSI2adKZgrqFZB6hwCVJHMdRJhqlmALnZa1z45HUI989V295mE17bMgK8MUkOvy260V0x9gjDMpXkDcpxkwvaswo68yM5ggomVg", "genre": 18 }] } $.each(data.response, function(indx, el) { $("<li/>", { html: "artist : " + el.artist + "<br> title: " + el.title, click: function() { alert(el.url); } }).appendTo("ul") }); }) 
 ul { list-style: decimal; } 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> <ul></ul> 

  • and if the answer is not one such line, and N - aleksey
  • @aleksey then what is the output format - go loop through the entire data.response array and output where you need - rony
  • In general, my titlt + artist is displayed in the list, and I need to select one item from a sysk, its url was written to a variable, which I can then use - aleksey
  • @aleksey I do not understand your problem, you were shown how to get variables, go loop and do what you need with any variables - rony
  • @aleksey see the answer again - roni