I am creating a Dynamic JSON using ExpandoObject and IDictionary.
My Sample Code is as below :
DataTable dt_MappedColumns = new DataTable();
dt_MappedColumns.Columns.Add("Sr.No");
dt_MappedColumns.Columns.Add("TColumnName");
dt_MappedColumns.Columns.Add("AColumnName");
dt_MappedColumns.Rows.Add("1", "Apple", "Lion");
dt_MappedColumns.Rows.Add("2", "Orange", "Tiger");
dt_MappedColumns.Rows.Add("3", "Mango", "Fox");
dt_MappedColumns.Rows.Add("4", "Orange", "Wolf");
var dictionary1 = new Dictionary<string, object>();
foreach (DataRow dr in dt_MappedColumns.Rows)
{
string key = dr["TColumnName"].ToString();
string value = dr["AColumnName"].ToString();
if (!dictionary1.ContainsKey(key))
{
// key does not already exist, so add it
dictionary1.Add(key, value);
}
else
{
// key exists, get the existing value
object existingValue = dictionary1[key];
if (existingValue is string)
{
// replace the existing string value with a list
dictionary1[key] = new List<string> { (string)existingValue, value };
}
else
{
// the existing value is a list, so just add the new value to it
((List<string>)existingValue).Add(value);
}
}
}
string Manjson = JsonConvert.SerializeObject(dictionary1);
The JSON String so Obtanined is as below with Escape character {\}:
"{\"Apple\":\"Lion\",\"Orange\":[\"Tiger\",\"Wolf\"],\"Mango\":\"Fox\"}".
I wish to remove the Escape character {\} and desired JSON would be like below :
"{"Apple":"Lion", "Orange":["Tiger","Wolf"], "Mango":"Fox"}"
**** EDIT ****
Interestingly, if I print the JSON in console, it is without Escape Character, but when I insert into Oracle DB Table it inserts with Escape Character.
Using Visual Studio 2010 Professional with Oracle 11g and PL/SQL 11.2
What would be the solution for this :
Any help is appreciated :)