Home > Net >  How to access an Object property that came from an HTTP Post in Angular
How to access an Object property that came from an HTTP Post in Angular

Time:01-18

> `{
    "profilePicture": null,
    "loginUser": {
        "id": 16,
        "fullName": "Admin",
        "email": "adminDummy",
        "birthdate": null,
        "uid": null,
        "dn": null,
        "mail": "adminDummy",
        "hellaDepartment": null,
        "hellaManager": null,
        "hellaSex": null,
        "telephoneNumber": null,
        "hellaDepartmentSuperior": null,
        "hellaShortTelephoneNumber": null,
        "hellaPhyLocality": null,
        "hellaExtEmpYN": null,
        "hellaCountry": null,
        "hellaCardNumber": null,
        "userRoles": [
            "ADMIN",
            "DEVELOPER",
            "LEVEL1",
            "LEVEL2",
            "LEVEL3",
            "LEVEL4"
        ],
        "confirmedRegistration": true,
        "accountDeactivated": false,
        "pin": "1234567890120",
        "accountBlocked": false,
        "level1": true,
        "level3": true,
        "level2": true,
        "admin": true,
        "level4": true
    }
}`

I want to acces ' "id": 16, ' in order to make some logic

I just need help !!!

CodePudding user response:

var data = { "profilePicture": null, "loginUser": { "id": 16, "fullName": "Admin", "email": "adminDummy", "birthdate": null, "uid": null, "dn": null, "mail": "adminDummy", "hellaDepartment": null, "hellaManager": null, "hellaSex": null, "telephoneNumber": null, "hellaDepartmentSuperior": null, "hellaShortTelephoneNumber": null, "hellaPhyLocality": null, "hellaExtEmpYN": null, "hellaCountry": null, "hellaCardNumber": null, "userRoles": [ "ADMIN", "DEVELOPER", "LEVEL1", "LEVEL2", "LEVEL3", "LEVEL4" ], "confirmedRegistration": true, "accountDeactivated": false, "pin": "1234567890120", "accountBlocked": false, "level1": true, "level3": true, "level2": true, "admin": true, "level4": true } }

data["loginUser"]["id"]

Assuming the object you provided is saved the variable data

You can learn more about Dictionaries in this article

I hope this helps :)

  • Related