Reputation: 4508
In my ts file I have function which sends some data and then receives json response
const fd = new FormData();
this.service.uploadImage(fd).subscribe(
(res:any)=>
{
console.log(res) ;
In this way I get the whole json console.logged.
{item1: "abcdefg", item2: "xyz"}
But I want to access each component of json seperately. How can I do that ?
Upvotes: 0
Views: 50
Reputation: 440
Actually it depends on the format of JSON response you are getting, but in this particular case, you can do this by .
operator, like
res.item1
res.item2
Upvotes: 1
Reputation: 1843
your console log look like an object not a json, so i don't think you need to parse, you can just access res.item1 to get value one
If it does not work and indeed is a json first parse your string via const parsedRes = JSON.parse(res)
Upvotes: 0