Consider a string which is
{"Table" : [{"Bird" : "Peacock"},
{"Bird" : "Crow"}]}
to this ["Peacock", "Crow"] in jquery… Is this possible?
EDIT:
I am doing this but didnt work…
$(document).ready(function() {
var obj = JSON.parse('{"Table" : [{"Bird" : "Peacock"},{"Bird" : "Crow"}]}');
myarray = [];
$.each(obj.table, function(i, v) {
myarray.push(v.Bird);
});
$("#tags").autocomplete(myarray, {
width: 138,
max: 4,
highlight: false,
multiple: true,
multipleSeparator: " ",
scroll: true,
scrollHeight: 300
});
});
You can use the
parseJSONmethod (requires jQuery 1.4.1 or later) to parse the string, then themapmethod to get theBirdproperty from each item:If it’s not a string but an object, you just need the
mapmethod: