Skip to content

Instantly share code, notes, and snippets.

@Denchyaknow
Created July 18, 2023 10:08
Show Gist options
  • Save Denchyaknow/45e95dc99b8beb853923a972ec91c440 to your computer and use it in GitHub Desktop.
Save Denchyaknow/45e95dc99b8beb853923a972ec91c440 to your computer and use it in GitHub Desktop.
A HowTo on Converting incomming Json data as a Custom Datatype
//Say you have incommingJson like this:
{
"name": "Bob",
"url": "https://example.com/bob.png"
}
//And you have a DataClass like this you use for you Avatar Loading or Refferences
[System.Serializable]
public class AvatarData
{
public string AvatarName = "404";
public string AvatarUrl = string.Empty;
// ...
}
//You can add the JsonProperty(string) attribute to map the incomming data to the class properties
using Newtonsoft.Json;
[System.Serializable]
public class AvatarData
{
[JsonProperty("name")]
public string AvatarName = "404";
[JsonProperty("url")]
public string AvatarUrl = string.Empty;
// ...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment