I have some data from the bind grid view and I want to display them in a serialized format. Right now I have a nested array where the above parent is serialized correctly but the child array has escape characters and slashes.
private List<string[]> gridDataList = new List<string[]>();
private void BindGridView()
{
string ss = cb_DOCUMENT_NO.SelectedValue;
List<Dictionary<string, string>> MainList = new List<Dictionary<string, string>>();
Dictionary<string, string> rowData = new Dictionary<string, string>();
rowData["User_id"] = user_id;
rowData["Region_Id"] = txt_REGION_ID.Text;
rowData["document_no"] = ss;
rowData["industry_name"] = cb_INDUSTRY_NAME.SelectedValue;
rowData["customer_number"] = cb_INDUSTRY_NAME.SelectedValue;
rowData["posting_date"] = txt_POSTING_DATE.Text;
List<Dictionary<string, string>> paymentList = new List<Dictionary<string, string>>();
foreach (GridViewRow row in biGridView.Rows)
{
Dictionary<string, string> paymentData = new Dictionary<string, string>();
for (int i = 0; i < row.Cells.Count; i++)
{
string headerText = biGridView.HeaderRow.Cells[i].Text.Trim();
string cellText = row.Cells[i].Text.Trim();
if (cellText == " ")
{
cellText = string.Empty;
}
paymentData[headerText] = cellText.Trim();
}
paymentList.Add(paymentData);
}
rowData["payment_for"] = JsonConvert.SerializeObject(paymentList);
string jsonData = JsonConvert.SerializeObject(rowData, Formatting.Indented);
Response.Write("<pre>" + jsonData + "</pre>");
PostJsonDataInLaravelApp(jsonData);
}
Obtained output:
{
"User_id": "EAUSER02",
"Region_Id": "ID-02",
"document_no": "02-80/81-BIN-00259",
"industry_name": "02-CNO-0001",
"customer_number": "02-CNO-0001",
"posting_date": "03-05-2080",
"payment_for": "[{\"BillType\":\"गोदाम भवन बहाल\",\"Description\":\"गोदाम भवन बहाल\",\"Amount\":\"1000.00\",\" \":\"\"}]"
}
Expected output:
{
"User_id": "EAUSER02",
"Region_Id": "ID-02",
"document_no": "02-80/81-BIN-00259",
"industry_name": "02-CNO-0001",
"customer_number": "02-CNO-0001",
"posting_date": "03-05-2080",
"payment_for": [
{
"BillType": "गोदाम भवन बहाल",
"Description": "गोदाम भवन बहाल",
"Amount": "1000.00",
" ": ""
}
]
}