0

I'm trying to access the roomName, but so far I am unable. I don't get how to get past the barriar of the info.[long ID with dashes].roomName.

At most I can get back the object of the long id or undefined.

I have tried info[0].roomName. Trying to get the first object in the info and then go on from there. The long id number is also in list.id, I don't know if that can help.

I would have set the info as an array like list is, but this is not my JSON, only one that I am working with.

    {  
       "list":[ IGNORE, can access code here ],
       "info":{  
          "e5eb1ccf-bd45-4d01-8e2a":{  
             "id":"e5eb1ccf-bd45-4d01-8e2a",
             "name":"Lucy",
             "roomName":"Arts" <<I need to get to this.
         }
    }
 }

I hope this makes sense, first post and this is just a boiled down version of what I have. Putting in the id number in the info.e5eb1ccf-bd45-4d01-8e2a.roomName breaks after the first -

L.Jack
  • 1

1 Answers1

1

Once you've parsed the JSON (assuming you even have JSON*) and you have an object, you'd use brackets notation:

var room = theObject.info["e5eb1ccf-bd45-4d01-8e2a"].roomName;
console.log(room); // Arts

* Remember, JSON is a textual notation for data exchange. (More here.) If you're dealing with JavaScript source code, and not dealing with a string, you're not dealing with JSON.

T.J. Crowder
  • 1,031,962
  • 187
  • 1,923
  • 1,875