I have a JSON array that has multidimensions to it:

{
      "@id": "a",
      "@label": "A",
      "drecord": [
         {
            "@id": "aaliyah",
            "@rdate": "2001-08-25",
            "@lease": "bh05",
            "name": {
               "surname": "Aaliyah"
            },
            "job": "hip hop singer/actress",
            "dead": {
               "@value": "y"
            },
            "cause": "Burned to death in a plane crash",
            "ddate": {
               "date": "2001-08-25"
            },
            "bdate": {
               "date": "1979-01-16"
            },
            "other": {
               "#text": [
                  "Full name: Aaliyah Dana Haughton, was to have appeared in the second and third",
                  "movies."
               ],
               "movie": "Matrix",
               "home": {
                  "@id": "http://www.aaliyahEbertonline.com/"
               },
               "imdb": {
                  "@id": "Aaliyah"
               },
               "fg": {
                  "@id": "5727911"
               }
            }
         },

and i am trying to use the jQuery Auto Complete to get the name and surname to populate...right now all its doing is returning blank results when i type in a name like "aaliyah".

here is my jQuery Code:

$( function() {

    $( "#birds" ).autocomplete({
      source: function( request, response ) {
        $.ajax( {
          url: "dpsportion.json",
          type: "GET",
          dataType: "json",
          data: {
            term: request.term
          },
          success: function( data ) {
            response( data );
          }
        } );
      },
      minLength: 2,
      select: function( event, ui ) {
        console.log( "Selected: " + ui.item.drecord.name.fname + " aka " + ui.item.drecord.name.surname );
      }
    } );
  } );

what am i doing wrong? I thought i had to reference the line that i want like drecord.name or drecord.surname

ui.item.drecord.name.fname

drecord from your json is an array ([...]) - so you need an index - and I don't see fname as a property under name - so I changeed it to surname - perhaps this would work...

 ui.item.drecord[0].name.surname

From your example...

{
    "drecord": [
         {
            "name": {
               "surname": "Aaliyah"
            }

I'm assuming the snippet is the for ui.item and that it's not part of an array, in which case you'd need ui.item[0].drecord[0].name.surname

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.