Home  >  Q&A  >  body text

How to access "type" property in "students" array in API response using Flutter, Laravel and PHP?

"data": {
    "id": 9,
    "name": "tala",
    "role": "Student",
    "email": "tala@gmail.com",
    "students": [
        {
            "id": 1,
            "name": "tala",
            "type": "Master_Degree",
            "year": "third",
            "Semester": null,
            "specializations": "جراحة",
            

        }
    ]
},

I used to receive emails by doing this: Response['data']['email']

How to get "type" from response['data']['student']? ?

P粉744831602P粉744831602171 days ago282

reply all(1)I'll reply

  • P粉311089279

    P粉3110892792024-04-05 12:10:16

    In your data object, students is an array of objects!

    So many students can be added!

    To access the student attribute, you must loop into the student array.

    $students = response["data"]["students"];
    
    foreach($students as $student ) {
      //access to each student in your list
      // do what ever you want
    }

    reply
    0
  • Cancelreply