✅ [RESOLVED] Newtonsoft :: wrong serialization format
Dear all,
I'm requesting your help, because I don't understand what I'm doing wrong.
`
I need this data with this format:
But I'm getting it like this:
`
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
8 Replies
Just use a proper class
operations
is a string, so the serializer will treat it as such
Make it an array, and it'll be treated as an array@Angius sorry this question, but I need to do it: if I'm not wrong the Array doesn't allow me to use custom Key (index), but I need to have the array like this: ["inumoper" = "4444"]
Use an object
Or whatever other structure you need
Could even use $jsongen
Instantly parse JSON in any language | quicktype
Whether you're using C#, Swift, TypeScript, Go, C++ or other languages, quicktype generates models and helper code for quickly and safely reading JSON in your apps. Customize online with advanced options, or download a command-line tool.
Convert JSON to C# Classes Online - Json2CSharp Toolkit
Convert any JSON object to C# classes online. Json2CSharp is a free toolkit that will help you generate C# classes on the fly.
And generate the classes from your desired JSON
Thank you so much. I will try.
@Angius and @MODiX
With the clarification about the object, I used this process:
Instead of creating an string array, I created the JObject array, so, in the serialization step, it took it as an Object.
It worked as I expected.
Why do you still insist on not using type-safe ways of creating JSON?
Still a ton of strings instead of using classes
Oh well, whatever works for you ig
To be honest, because I'm learning, and sometimes creating a lot of classes breaks my mind. But I will try to do it that way.
I need to practice that part to use classes for getting the objects as you recommend me.