So this was a frustrating lesson to learn – and please feel free to be entertained by my apparent stupidity.
I was trying to create my own JSON with an xAgent – seems easy enough. I created a simple output which looked like this
{ 'items': [ { 'name': 'AK', 'dc': 23 } ] }
and when I fed it through my AJAX code it failed.
$.ajax({ dataType: 'json', url: "http://copper.xomino.com/xomino/ExtjsBigData.nsf/xState.xsp?query="+query //url: 'http://copper.xomino.com/xomino/Extjs.nsf/xRestService.xsp/byFirstName?count=5' }).done(function(data){ console.log(data) }).fail(function(e){ console.log('FAIL') console.log(e) })
But what was interesting is that it returned the data (e) correctly. I was baffled and frustrated for way too long.
So I finally asked he correct question of google (isn’t that always the case) and I found that http://jsonlint.com/ was telling me the strings were incorrect…..
because JSON requires double ” and not single ‘
really?
This worked – changed the single to double quotes.
{ "items": [ { "name": "AK", "dc": 23 } ] }
and I am apparently now less stupid that I was yesterday…….
PS
Kathy recommends – http://json.parser.online.fr/
This tool is also a good one for JSON formatting and validating.
http://jsonformatter.curiousconcept.com/
Brilliant – thanks for adding Shean 🙂
It gets more fun if you add in weird Unicode characters: http://timelessrepo.com/json-isnt-a-javascript-subset
Actually, it makes you less ignorant than yesterday. Ignorance is the lack of knowledge, stupid is the lack of capacity. Since we share a ‘lack of capacity’, I can’t fault you for a ‘lack of knowledge’, especially when you share that knowledge!
Thanks, Marky!