Thanks all for the responses.

In case anyone reads this post ... This is what I did to get it
working:

The JSON data I had was:

{"vegetables":null,"fruit":["orange","apple","peach"]}

In my jsp (html, whatever) I had:

<head>

        <link rel="stylesheet" href="css/jquery.autocomplete.css" type="text/
css" media="screen"/>
        <script type="text/javascript" src="javascript/jquery-1.2.6.js"></
script>
        <script type="text/javascript" src="javascript/
jquery.autocomplete.js"></script>

        <script type="text/javascript">
        $().ready(function() {

                function parse(data) {
                        var parsed = [];
                        var row = data.split("fruit")[1];
                        row = row.substring(3, row.length - 2);

                        var data = row.split(",");
                        var fruits = [parsed.length];

                        $.each(data, function(i) {
                                n = data[i].substring(1, data[i].length-1);
                                fruits[i] = {
                                        data: n,
                                        value: n,
                                        result: n
                                };
                        });

                        return fruits;
                }

           function formatItem(row) {
                  return row;
           }

                $("#fruit_input").autocomplete("myaction.action", {
                        parse:parse,
                        formatItem: formatItem
                });
     });

    </script>
</head>

the jquery.autocomplete.js file I just copied from:

http://dev.jquery.com/view/trunk/plugins/autocomplete/

I had a struts action to give me the JSON data. I simply followed the
example here:
http://cwiki.apache.org/S2PLUGINS/json-plugin.html
(somewhere towards the bottom of the page).

I hope that helps someone!
Cheers everyone!

Reply via email to