سؤال

I'm not very experienced in this stuff, but I simply call an API wich returns me this

[
   {
      "beatmapset_id":"18860",
      "beatmap_id":"66609",
      "approved":"2",
      "approved_date":"2010-08-15 10:04:19",
      "last_update":"2010-08-15 10:00:44",
      "total_length":"468",
      "hit_length":"447",
      "version":"Legend",
      "artist":"DragonForce",
      "title":"Revolution Deathsquad",
      "creator":"Lesjuh",
      "bpm":"250",
      "source":"",
      "difficultyrating":"3.95095",
      "mode":"0"
   }
]

my html :

$(document).ready(function(){    

$.getJSON('whatever.html', function(fbResults) {

document.write(fbResults.beatmapset_id);

     });

}); 

Now the problem is, it doesn't work this way, but it works if I remove the "[" and "]" from the JSON code.

Well, I can't just tell the guy who made this API to remove those, what could I do?

Edit: There is another problem now. https://osu.ppy.sh/api/get_beatmaps?k=5051a27169de8f360636fb0c3a108e8a3dab24b2&b&b=66609 if I take this as the link, it doesn't work. I tried it with callback but this doens't work either. https://osu.ppy.sh/api/get_beatmaps?k=5051a27169de8f360636fb0c3a108e8a3dab24b2&b&b=66609?callback=?'

هل كانت مفيدة؟

المحلول

The square brackets means that this is an array containing one item.

To get the first (and only) item in this array, simply append [0] to it.

In your example:

document.write(fbResults[0].beatmapset_id);

نصائح أخرى

Try fbResults[0].beatmapset_id

EDIT: See Andrew Shepherd's answer for more explanation :P

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top