I’ve got a response json from Amazon AWS and I’m trying to serialize it back to a class and am not sure why it’s not working. I’ve used the jsonUtility for arrays before and it was fine, I’ve searched through threads, and am stuck wondering if I need to use a different json serializer.
This is the json I’m getting from the server
These are the classes I made to serialize it to:
[System.Serializable]
public struct AWSResponse
{
public string statusCode;
public body body;
public header headers;
}
[System.Serializable]
public struct body
{
public List<Item> Items;
public string Count;
public string ScannedCount;
}
[System.Serializable]
public struct Item
{
public string timedate;
public float latitude;
public string device;
public float longitude;
}
[System.Serializable]
public struct header
{
public string ContentType;
}
And when I try to serialize it, statusCode gets populated but nothing after that gets populated.
AWSResponse resp = JsonUtility.FromJson<AWSResponse>(s);
print("Response Serialized: \nstatusCode: " + resp.statusCode
+ " " + resp.body.Items.Count);
Items count is 0 in the console.
edit:: So after reconstructing it the opposite way (new instance and populate variables then serialize to json and compare strings) I noticed the json from amazon has “body”: “{items stuff}” with the curly brackets in quotes and the jsonutility version doesn’t, it’s just “body”: {} .