Convert JSON String to Unity C# String – Not Deserializing, Not Converting Into An Object
I have looked everywhere for the answer to this. I have a complicated, serializable Unity object, which captures various pieces of information (including complicated nested objects) about touchscreen events. For various reasons, especially performance, I cannot save the object directly into a list and send up the data and properties for this object up to my back-end.
Therefore, I have opted to save a serialized version of this object and send it up to my database. However, my database seems to store escaped JSON when I store the object as serialized JSON. There are 1) double quotes after the brackets that open up the object; and then quotes separating every object in the JSON array.
For example:[“{“eventID”:”2e9586d27f2e2257adc87e1ec1f437… “] and then ” ” encapsulating individual other objects in the array.
All I am trying to do is to convert a serializable object into plaintext basically. How do I do this? I have tried doing everything – trimming, replacing letters in the string, converting to a byte array and de-converting. I simply want to find a method of storing the object and its properties as a string; converting everything into a dictionary would be hugely time-consuming, and I think it would be best if I just figured out a way of easily converting to valid JSON from here.
How can I get it to look like this: [{“color”: null, “end_pos”: null, “end_time”:…”? Thanks for any help!
CODE is here:
string jsonString = JsonConvert.SerializeObject(newTouch);
allTouches.Add(jsonString);
- newTouch is of type TouchEvent.
TouchEvent uses [System.Serializable]. Should I not be serializing this object again? If not, how do I use it and store it in a List of strings?
EDIT: Added a picture. As you can see the events in the first few rows are ones where the object is stored. The events below are ones where the json string is stored. I want them to be escaped, and in the right valid format, but they’re not. Is there perhaps a way of taking how the object would be stored and making that into a string?
Read more here: Source link

