I have json data being returned as a collection:
var foo = ["6", "7", "33"]
using JSONP in jQuery. Since I’m using JSONP, the data is being returned to a callback function, which is interpreting it as a string instead of a collection. Do I need to run eval(foo) on the string in the callback before handling it as a collection, or is there some other means of recasting it?
If you’re using jQuery, you should be doing
.ajaxwithdataType: "jsonp", which should send the parsed data to your callback, rather than a string. If this doesn’t work for you, or there are other complexities I’m not seeing, you can use$.parseJSON(foo)instead ofeval(foo). This will call the browser’s nativeJSON.parsemethod if it exists, or useevalif it doesn’t.