How To Return Multiple Result In New Line Using JSON.parse In Angular?
I have json file with multiple results. 1 -- Sample one jsonChanges: '{'field':'cancerType','oldValue':'Lentigo maligna melanoma','newValue':'Primary malignant melanoma of g canal'
Solution 1:
you can use this code in your component:
this.str='{"field":"referringPhysician","oldValue":"Medical oncologist","newValue":"Cardiac surgeon"},{"field":"cancerType","oldValue":"Lentigo maligna melanoma","newValue":"Primary malignant melanoma of g canal"}';
this.arrData=this.str.split('},');
this.arrData.forEach((val, key) => {
if(key != this.arrData.length-1){
this.allData.push(JSON.parse(val+'}'));
}else{
this.allData.push(JSON.parse(val));
}
});
console.log(this.allData);
then you have to user *ngFor in your html file
Solution 2:
Adding additional array and getting results from this array solved my solution.
try {
this.results = [];
this.totalItems = result.recordsCount;
this.auditTrailList = result.lstRecords;
this.auditTrailList.forEach(x => {
const jschanges = JSON.parse(`[${x.jsonChanges}]`);
jschanges.forEach(z => {
this.results.push({
userName: x.userName,
timestamp: x.timestamp,
entityName: x.entityName,
field: z.field,
oldValue: z.oldValue,
newValue: z.newValue
})
})
});
Post a Comment for "How To Return Multiple Result In New Line Using JSON.parse In Angular?"