Skip to Content

How can i access nested json elements(firstname and lastname) in js view ?

{
 "courses": [

  {
   "req_id": "1",
   "name" : "ABAP OO Basics",
   "start" : "20-08-2014",
   "end" : "22-08-2014",
   "starttime": "10:00:00",
   "endtime": "16:00:00",
   "status": "Booked",
   "room": "Room CDE",
   "adress" : "Adress No.1",
   "street": "Street No.1",
   "zip_code": "74892142578485",
   "city": "City No.1",
   "country": "Country No.1",
   "phone": "0595726764675435497436497",
   "fax":"12",
   "cap_min": "10",
   "cap_opt": "20",
   "cap_max": "30",
   "img": "./res/1.jpg",
   "content": "Test",  
   "participant":  [{   "firstname": "Maik",
                        "lastname": "Maier",
                        "job": "installer",
                        "company": "muster" 
                    },
                    {   "firstname": "Marco",
                        "lastname": "Schmidt",
                        "job": "installer",
                        "company": "schmitt" 
                    },
                    {   "firstname": "Hans",
                        "lastname": "Mueller",
                        "job": "installer",
                        "company": "muster" 
                    },
                    {   "firstname": "Matthias",
                        "lastname": "Gottlieb",
                        "job": "installer",
                        "company": "schmitt" 
                    }]

  }
 ]
}
Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • Feb 07 at 01:47 PM

    With standard javascript the first entry is accessible using

    var myData = <your json structure>

    myData.courses[0].participant[0].firstname

    so you could just loop on the courses array and then within it, loop on the participant array to get all of them.

    Regards,

    Jamie

    Add comment
    10|10000 characters needed characters exceeded