Json Response

Told to request Json data by using the following code. If I leave the question mark at the end I get an invalid message when I run it through http://jsonlint.com as there is a question mark at the beginning of the Json. Taking that out appears to solve the problem but I'm not 100% sure that that is ok?

If I leave the question mark at the end I get an invalid message when I run it through http://jsonlint.com as there is a question mark at the beginning of the Json. Taking that out appears to solve the problem but I'm not 100% sure that that is ok?

When I view the code in debugger I get " SyntaxError: Unexpected token ':' ", but this response is coming from an API so I am unsure what I can do about it?

Updated

You are using json variable as parameter and looping using data, $.each(data["resultsPage"]["results"]["event"] should be $.each(json["resultsPage"]["results"]["event"] at first.
–
The AlphaFeb 17 '13 at 23:17

Thanks... I think I've been staring at this screen for too long!
–
MichaelFeb 17 '13 at 23:20

What is the question? "It doesn't work" is not enough information to go off of. Are you getting any error messages? Have you stepped through your code with a debugger?
–
gilly3Feb 20 '13 at 21:59

@gilly3 Perhaps not the clearest question but I was very tired when I wrote it! I'm just completely at a loss, I've spent hours making small changes to see if they have an effect and nothing... I hadn't been getting any errors but I am not getting one from my Json Response, "Unexpected ':'"... But this responce is coming from an API so not too sure what I can do about it?
–
MichaelFeb 21 '13 at 10:09

Your json is invalid, "resultsPage:" { should be "resultsPage" : {, the colon is inside the double quotes, you can validate your json using jsonlint.com. Here is an example using valid (edited) json which is printing lat, lng in the console.

That response I posted earlier was taking from the documentation and as you know was wrong!!! Sorry for wasting your time. I've updated my answer with a real response, which I have ran through jsonlint.com and it came back as valid.
–
MichaelFeb 18 '13 at 9:18

@Michael, Pleaase check the updated answer and see what you get, actually I'm still not sure what question mark your talking about.
–
The AlphaFeb 26 '13 at 23:43

at the end of the API request "&jsoncallback=?"... It's this that has been confusing me, with it I get an error but I kind of assumed it was needed or why else would they include it!
–
MichaelFeb 27 '13 at 9:48

Then, you don't need (probably) a json callback, since you are already using one after the comma (2nd parameter to getJSON function).

So you can simply delete the &jsoncallback=? from your URL and make it to http://api.songkick.com/api/3.0/events.json?location=clientip&apikey={your_api_key}

Here's what is going on -

-- To facilitate JSONP (and Cross Domain AJAX request) you are sending a callback function to the URL

-- The Server then reads the jsoncallback=XYZ and then returns you the data wrapped inXYZ function call

-- So that you can define XYZ function in your JavaScript somewhere
like the following:

function XYZ(jsonDATA) {
// ... And do things Here. JSONP is cool !
}

-- But Since you already have a functioning callback to the getJSON function, you don't need the &jsoncallback=something and can therefore delete it

PS: as a proof to above, try hitting the URL http://api.songkick.com/api/3.0/events.json?location=clientip&apikey={your_api_key}&jsoncallback=MyFunction in your browser and you will get the following response in one line:

Thankyou for your response, especially for trying to explain to me exactly what was going on and not just telling it was fine to drop it... I have ran it through JSONLINT and it is fine... But my console says there is an unexpected ':', you think it's alright tho?
–
MichaelFeb 26 '13 at 21:46

@Michael, console is giving error because you are executing the JSON response as a JavaScript code. Its a valid JSON but not valid JavaScript. If you put var abc = before your JSON in console, the error is gone !!
–
Om ShankarFeb 27 '13 at 17:01

@Michael, also, you have accepted an answer which is an alternate solution. The answer says the API does not support callback, which is wrong. I gave you an example of sending any_string_as_a_callback to songkick, and the JSON comes wrapped in the callback. So it does support !!
–
Om ShankarFeb 27 '13 at 17:12