I want to convert Json string into object and render it's specific value in JQuery Datatable Cell. I tried several hours for this but didn't able to achieve.
Json Example
[
{ "id":1, "Error": "Name missing in datatable"},
{ "id":2, "Error": "{\"ErrorType\": \"401\", \"InnerException\":\"Invalid request, Please correct and submit\"}" }
]
First I want to check if Error is normal string or json string, if normal string show as it is and if json string convert it into json object and render InnerException into datatable cell. i tried following code but didn't get correct result.
My code Example
var RespTable = $('#dtResponse').DataTable({
data: dataList,
columns: [
{ "title": "ID", "data": "id", "defaultContent": ""},
{
"title": "Error Message",
"data": "Error",
"defaultContent": "",
"render": function (data, type) {
var obj = JSON.parse(data)
if (obj != undefined)
return obj.InnerException;
else
return data
}
}
]
});