© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•4y ago•
18 replies
jgomezal

✅ [RESOLVED] Newtonsoft :: wrong serialization format

Dear all,

I'm requesting your help, because I don't understand what I'm doing wrong.

 string operations = "{\"inumoper\": \"44444\", \"itdoper\": \"ORD1\"}";

Dictionary<string, string> objParams = new Dictionary<string, string>
{
    {"accion", "LOAD" },
    {"operaciones", operations},
};

string[] arrParams = new string[4];
arrParams[0] = JsonConvert.SerializeObject(objParams, Formatting.None);
arrParams[1] = "123456789";
arrParams[2] = "1001";
arrParams[3] = "0";

Dictionary<string, Array> objSend = new Dictionary<string, Array>
{
    {"_parameters", arrParams }
};          
 string operations = "{\"inumoper\": \"44444\", \"itdoper\": \"ORD1\"}";

Dictionary<string, string> objParams = new Dictionary<string, string>
{
    {"accion", "LOAD" },
    {"operaciones", operations},
};

string[] arrParams = new string[4];
arrParams[0] = JsonConvert.SerializeObject(objParams, Formatting.None);
arrParams[1] = "123456789";
arrParams[2] = "1001";
arrParams[3] = "0";

Dictionary<string, Array> objSend = new Dictionary<string, Array>
{
    {"_parameters", arrParams }
};          
`

I need this data with this format:
"{\"_parameters\":[{\"accion\":\"LOAD\",\"operaciones\":[{\"inumoper\":\"44444\",\"itdoper\":\"ORD1\"}]},\"123456789\",\"1001\",\"0\"]}"
"{\"_parameters\":[{\"accion\":\"LOAD\",\"operaciones\":[{\"inumoper\":\"44444\",\"itdoper\":\"ORD1\"}]},\"123456789\",\"1001\",\"0\"]}"


But I'm getting it like this:
"{\"_parameters\":["{\"accion\":\"LOAD\",\"operaciones\":\"{\\\"inumoper\\\": \\\"44444\\\", \\\"itdoper\\\": \\\"ORD1\\\"}\"}"]},\"123456789\",\"1001\",\"0\"]}"
"{\"_parameters\":["{\"accion\":\"LOAD\",\"operaciones\":\"{\\\"inumoper\\\": \\\"44444\\\", \\\"itdoper\\\": \\\"ORD1\\\"}\"}"]},\"123456789\",\"1001\",\"0\"]}"
`

As you see, in the "operaciones" array, I'm receiving an escape for a backslash and I don't need it. Do you know how can I solve it?

Thanks in advance,
Migue
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

NewtonSoft Serialization Exception
C#CC# / help
2y ago
Newtonsoft.Json Serialization Exception
C#CC# / help
3y ago
Force Newtonsoft to deserialize into certain formats
C#CC# / help
16mo ago
Newtonsoft JsonConverter to replicate the serialization of the JsonObjectAttribute on an IEnumerable
C#CC# / help
4y ago