Hey there, I am receiving a JSON string from the backend of my webserver. I managed to create a class for User profile and mapped it with the exact fields as its JSON string. Unfortunately the Items JSON string has nested values. How can I create an object based on the number of items in my JSON string?
When I parsed the User JSON string to a class I used this code (the class had strings for each of the values - The Items JSON string has multiple items):
Although the user inventory class is empty as I dont really know how to structure it compared to UserProfile class. There were no nested values in UserProfile so I could just make public strings with the same value name in the JSON.
Here is my UserProfile class:
[System.Serializable]
public class UserProfile
{
public string displayName;
public string firstName;
public string email;
public string age;
public string haircolor;
}
It was straight forward as there were not two values with the same name (nothing nested in the JSON). But the Items JSON has strings with the same name; name, stock, sku, etc.
I was not successful in storing the user data as a dictionary, so i resorted in creating a class to parse the JSON values. Could you perhaps point me to some good documentation or tutorials on Dictionaries. I just couldnt wrap my head around them when I was trying the parse the JSON values.
I have cleaned up my code into a switch statement. The USERINFO switch statement works, as per the UserProfile class I posted above. But how would i structure my UserInventory class in a similar fashion to UserProfile?