首頁  >  問答  >  主體

如何使用 Flutter、Laravel 和 PHP 存取 API 回應中「students」數組中的「type」屬性?

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

        }
    ]
},

我曾經透過這樣做來接收電子郵件: 回應['資料']['電子郵件']

如何從回應['data']['student']中取得「類型」? ?

P粉744831602P粉744831602171 天前276

全部回覆(1)我來回復

  • P粉311089279

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

    在您的data物件中,學生是一個物件陣列!

    可以增加這麼多學生!

    要存取學生屬性,您必須循環到學生陣列中。

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

    回覆
    0
  • 取消回覆