var var1 = JSON.parse('[{"ItemId":1, "ItemName":"item 1\"", "Unit":"Nos","Remarks":null, "ConsumedQuantity":1.00},
{"ItemId":1253, "ItemName":"item 2", "Unit":"Nos", "Remarks":null, "ConsumedQuantity":1.00}]');
var1.forEach(function (e) {
Object.keys(e).forEach(function (key) {
if (e[key] == id) {
//doing some stuff here
}
});
});
This code works perfectly when the value in the JSON doesn't contain double quotes. This JSON is produced from a list of Model in MVC.
I use @Html.Raw(Json.Encode(ViewBag.materialDetails)) to convert the list to JSON. When there is a double quote, then it doesn't enter into the forEach.
Any help is appreciated :)
"ItemName":"item 1\\""