Im using jquery and dojo to search a json string
$.get('json.txt', function(data) { //alert(data); works fine
dojo.require("dojox.json.query");
query = "(product_tonnage = "+$('#slider-tonnage-value').val()+")";
var json_db = jQuery.parseJSON(data);
var results = "";
results = dojox.json.query(query, json_db);
alert(results.length); //it must contain 4 results
});
How ever im getting the error “JSON.parse: unexpected non-whitespace character after JSON data”
jQuery’s
$.get()method (and other Ajax methods) will parse the JSON for you (assuming the MIME type of the response is right). You can also add a “json” parameter to the end of your$.get()call to explicitly tell jQuery you expect JSON back.Calling
JSON.parse()yourself will then try to parse an (already parsed) object rather than the JSON string.