Created
July 18, 2023 10:08
-
-
Save Denchyaknow/45e95dc99b8beb853923a972ec91c440 to your computer and use it in GitHub Desktop.
A HowTo on Converting incomming Json data as a Custom Datatype
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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