I have this type of json:[{"__data__":{"name":"student","group":1,"number":30,"foreignLanguage":true,"mark":10,"friend":"Alex"}}]
How can I access friend's name in Angular instantly and put it into a variable?
Asked
Active
Viewed 177 times
-2

Viktor
- 79
- 1
- 8
-
Where is your JSON ? What's your file structure ? Do you get it from an Http request ? What did you tried already ? – Emilien Mar 15 '21 at 12:59
-
`response[0]['__data__']['friend']`? Why is it an array and why is it enclosed in `__data__` property if the object needs to be directly accessed? If you get it from back-end, try to return only the object that is required. Then you could do `response['friend']`. – ruth Mar 15 '21 at 12:59
-
@MichaelD it is get from the backend, but I don't know how to make modifications to the code to return only the required object – Viktor Mar 15 '21 at 13:04
-
@Viktor Please provide some code or context so we can help you with modifications. – Mosrainis Mar 15 '21 at 13:34
-
Does this answer your question? [Parse JSON in JavaScript?](https://stackoverflow.com/questions/4935632/parse-json-in-javascript) – Liam Mar 15 '21 at 13:46
1 Answers
-1
As stated here: https://angular.io/guide/http
You can do:
this.http.get(studentUrl) .subscribe((result) => {
this.student = result["__data__"];
});

JFPicard
- 5,029
- 3
- 19
- 43