I'm doing the maintenance of an angular website, I have a problem of display in the ng2 smart table , in a column it displays the json of an object, this is the error that the developer has made by receiving the list of transaction where the user and items are a json text, how can I parse them
ps this is the code :
this.data.doData('transaction','get').subscribe({
next:res=>{
console.log(res);
this.dataSource = [...res['transactions']]
console.log(this.dataSource)
},error:err=>{
console.log(err);
}
})
So actually you are getting the JSON string. To use it just do
JSON.parse(items)
andJSON.parse(user)
and you will get the parsed JSON (array for the items and pbject for the user)You can also use map in your service file and handle this parsing their so when you subscribe to the data in your component's ts file you will get the parsed form.
UPDATE:
Look at the quotes (quotes matching you would know from basic rules of strings, i.e. either single or double should be enclosing the main string). So when you were JSON parsing the string it wasn't taking it correct format to parse it.