Hi
I’m new to unity and i am sure there is an easy way to do it but I can’t find it in the web.
I have a server that returns all the responses in JSON and all the keys are lower case with an underscore.
my classes property names are all camel case, so in the conversation from JSON to object i need to convert the keys to match my class keys and the opposite way for example :
json : {“first_name”:“bla” , “last_name”:“foo”}
and my class will be
class User
{
public string FirstName { get; set; }
public string LastName { get; set; }
}
There is. It’s known as a JsonProperty.
If you really need to use it because you don’t want to match your class to the json file, you can do this.
[JsonProperty(PropertyName = "first_name")] public string FirstName {get;set;}
Hi
im getting
The type or namespace name 'JsonPropertyAttribute' could not be found (are you missing a using directive or an assembly reference?) Assembly-CSharp
Yes, I didn’t give you all the answers. In visual studios you can right click on red squiggles to choose the lightbulb to see if it gives a solution. In this case, I’m using json.net which is in the Newtonsoft.Json namespace. If you aren’t using this for your json, you’ll need to see if whatever package you use implements json Attributes.
I see,
First of all thanks a lot (:
I installed Newtonsoft with visual studio using the nugget package manger and in the code, it does recognize it now, but when I open unity I get an error he does not recognize this package
Hi
I found how to install it from unity package manager Thanks!!!