When attempting to retrieve json
in the code below, an unexpected "space" is present after the opening brace and before the closing one:
{
"address": ......,
"filename": image.png,
"price": 12
}
If I use res.json()
in the following code, it results in a JSON parser
error. However, if I utilize res.text()
, it returns the string as expected. To address this issue, I attempted to remove the extra space by using replace.
this.http.get(Url)
.map(res => res.text())
.subscribe(data => {
JSON.stringify(data);
console.log(data.price);
});
Ultimately, the console logs undefined
instead of displaying the expected value of 12.
Upon switching back to using res.json()
, the following error message appears:
https://i.sstatic.net/RhSCk.png