Hey,
I am just wondering if they made something like the [JsonProperty] attribute for Unitys JSON.
Thanks.
Hey,
I am just wondering if they made something like the [JsonProperty] attribute for Unitys JSON.
Thanks.
As far as I’m aware of, no. Your property names must match the serialized json
Since this is based on Unity’s serializer, it’s possible that [FormerlySerializedAs] would work when deserializing. That’s quite the hack, though, and it won’t work when serializing.
You could implement it yourself, of course, by wrapping JsonUtil in your own code that inspects the type’s field for attributes, and processes the json before passing it on to JsonUtil.
I opened a feedback item for this
https://feedback.unity3d.com/suggestions/support-custom-variable-naming-in-json-de-serialization
You’ll need this asset: JSON .NET For Unity | Input Management | Unity Asset Store
That is outdated. If you want the latest JSON.NET you can use GitHub - applejag/Newtonsoft.Json-for-Unity: Newtonsoft.Json (Json.NET) 10.0.3, 11.0.2, 12.0.3, & 13.0.1 for Unity IL2CPP builds, available via Unity Package Manager
Which is now outdated, from now on, you should use the official Unity UPM package…
Install official via UPM · jilleJr/Newtonsoft.Json-for-Unity Wiki (github.com)
The best solution for me was using
using Newtonsoft.Json;
Then serializing the deserializing object with
JsonConvert.DeserializeObject<UserData>(json);
JsonConvert.SerializeObject(userData);
(Using normal JsonProperty)