Reputation: 358
I have the json in following format.
[{"tag":{"name":"& Awards","id":142}},{"tag":{"name":"& Bisexual Bars","id":207}},{"tag":{"name":"& Clubs","id":40}},{"tag":{"name":"& Imaging","id":1188}}}
and am using the following code
$("#tags_name").autocomplete({
source: "/companies/autocomplete_tags2.json",
width: 320,
dataType: 'json',
highlight: false,
scroll: true,
scrollHeight: 300,
parse: function(data) {
var array = new Array();
for(var i=0; i < data.tag.length; i++){
array[i] = {data: data.tag[i], value: data.tag[i].value, result: data.tag[i].id };
}
return array;
}
});
when i load the page the error i get is "newUncaught SyntaxError: Unexpected end of input"
What am i missing here?
Upvotes: 0
Views: 248
Reputation: 222080
Your parse function is wrong for the JSON you have. You have an array of Objects in your JSON.
It should be something like
parse: function(data) {
var array = new Array();
for(var i=0; i < data.length; i++){
array[i] = {data: data[i].tag, value: data[i].tag.name, result: data[i].tag.id };
}
return array;
}
Upvotes: 1