I am encountering an issue with displaying values from objects stored as string[] in appwriteDB. When trying to use *ngFor to iterate through the data, I faced difficulties. Despite attempting to convert the orderItems using JSON.parse(), the process failed due to unexpected white space detection.
[
{
"orderStatus": "New",
"orderPayment": "Paid",
"orderItems": [
"{\"productName\":\"Nokia Windows mobile\",\"productPrice\":299,\"productDetails\":\"Nokia windows 10 mobile\",\"productAvailable\":true,\"qty\":1,\"$id\":\"65f21c5cdd3449f30f68\",\"$createdAt\":\"2024-03-13T21:36:28.906+00:00\",\"$updatedAt\":\"2024-03-13T21:36:28.906+00:00\",\"$permissions\":[],\"$databaseId\":\"smartCartDB\",\"$collectionId\":\"Products\"}"
],
"$id": "65f6fcc4e65c46fc6e97",
"$createdAt": "2024-03-17T14:23:00.944+00:00",
"$updatedAt": "2024-03-17T14:23:00.944+00:00",
"$permissions": [],
"products": [],
"$databaseId": "smartCartDB",
"$collectionId": "Orders"
}, ...
Efforts to resolve this through JSON.parse have proven unsuccessful. What would be the most effective strategy for converting the specific orderItems object?
method:1
res.documents.map((el:any) => {return JSON.parse(el.orderItems)} ));
method:2
res.documents.map((el:any) => {
return el.orderItems.map((el2:any) => {return JSON.parse(el2)})
})
I seek guidance on the optimal approach to address my current predicament.