# Parse a List of Storage Objects in Unity

**URL:** https://forum.heroiclabs.com/t/parse-a-list-of-storage-objects-in-unity/727
**Category:** Local Setup
**Created:** [May 13, 2020, 11:47am UTC](https://forum.heroiclabs.com/t/parse-a-list-of-storage-objects-in-unity/727 "2020-05-13T11:47:32Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![EarthAdam](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/earthadam/32/259_2.png) [@EarthAdam](https://forum.heroiclabs.com/u/EarthAdam)
#### Post date: [May 13, 2020, 11:47am UTC](https://forum.heroiclabs.com/t/parse-a-list-of-storage-objects-in-unity/727/1 "2020-05-13T11:47:32Z")

</div>

I currently have a collection of “event” objects that I send to the storage engine. When I retrieve a list of all events for a user, they come back as a JSON string like this:  
`Cursor: , Objects: [`

```auto
Collection: events,
CreateTime: 2020 - 05 - 09T02: 53:58Z,
Key: circa5 / 8 / 2020 10:54:06 PM,
PermissionRead: 1,
PermissionWrite: 1,
UpdateTime: 2020 - 05 - 09T02: 53:58Z,
UserId: 16cbab61 - 62b4 - 479e-a8d5 - 8cad0dfd444a,
Value: {
     "Stop": "5/8/2020 10:53:51",
    "Start": "5/8/2020 9:53:51", 
    "Category": "2"
    }, 
Version: 1d2c8e71a3d3fea64346ac9ed1bbb899,
   , 
Collection: events, 
CreateTime: 2020 - 05 - 09T11: 41:20Z, 
Key: circa5 / 9 / 2020 7:41:29 AM, 
PermissionRead: 1, 
PermissionWrite: 1, 
UpdateTime: 2020 - 05 - 09T11: 41:20Z, 
UserId: 16cbab61 - 62b4 - 479e-a8d5 - 8cad0dfd444a, 
Value: {
     "Stop": "5/9/2020 7:39:43", 
     "Start": "5/8/2020 11:00:43", 
     "Category": "1"
      }, 
Version: 3217ca7796d46ba3b1984daad2d3229b, 
],

```

When I make Serializable classes for Objects and Values to parse through the response, I keep getting errors to the point that I’m manually editing the chars of the JSON response in order to get objects from the string. Is there any straightforward way to serialize these responses?

---

<div class="post-metadata">

### Author: ![novabyte](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/novabyte/32/1324_2.png) [@novabyte](https://forum.heroiclabs.com/u/novabyte)
#### Post date: [May 14, 2020, 1:24am UTC](https://forum.heroiclabs.com/t/parse-a-list-of-storage-objects-in-unity/727/2 "2020-05-14T01:24:52Z")

</div>

@EarthAdam What does your entity class look like that you serialize to and from? What JSON library do you have in your project to use as the decoder?

---

<div class="post-metadata">

### Author: ![EarthAdam](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/earthadam/32/259_2.png) [@EarthAdam](https://forum.heroiclabs.com/u/EarthAdam)
#### Post date: [May 14, 2020, 11:55am UTC](https://forum.heroiclabs.com/t/parse-a-list-of-storage-objects-in-unity/727/3 "2020-05-14T11:55:17Z")

</div>

@novabyte I’m using the JsonUtility from UnityEngine, and with that trying a mix of ways to match with either the “EventResponse” or “EventList” classes like so:  
`var result = await client.ListUsersStorageObjectsAsync(session4, "events", session4.UserId, limit, null);`  
`EventResponse eventResponse = new EventResponse();`  
`eventResponse = JsonUtility.FromJson<EventResponse>(result);`

Here are the classes:

```auto
[System.Serializable]
public class EventObject
{
    public int start;
    public int stop;
    public int category;
}

[System.Serializable]
public class EventList
{
    public string Collection;
    public string CreateTime;
    public string Key;
    public string PermissionRead;
    public string PermissionWrite;
    public string UpdateTime;
    public string UserId;
    public EventObject Value;
    public string Version;
}
[System.Serializable]
public class EventResponse
{
    public string Cursor;
    public EventList Objects;
}
```

---

<div class="post-metadata">

### Author: ![EarthAdam](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/earthadam/32/259_2.png) [@EarthAdam](https://forum.heroiclabs.com/u/EarthAdam)
#### Post date: [May 21, 2020, 12:31pm UTC](https://forum.heroiclabs.com/t/parse-a-list-of-storage-objects-in-unity/727/4 "2020-05-21T12:31:12Z")

</div>

Turns out you don’t have to de-serialize it at all, aside from once for the Value. Here’s the fix:

```auto
public async void Load_Events()
    {
        var session4 = await client.AuthenticateEmailAsync(email, password, username);
        Debug.LogFormat("New event: {0}, {1}", session4.Created, session4);

        //Check for devices associated to account
        const int limit = 100; // default is 10.
        var result = await client.ListUsersStorageObjectsAsync(session4, "events", session4.UserId, limit, null);
        foreach (var apiStorageObject in result.Objects)
        {
            var collection = apiStorageObject.Collection;
            var creationTime = apiStorageObject.CreateTime;
            var key = apiStorageObject.Key;
            var permissionRead = apiStorageObject.PermissionRead;
            var permissionWrite = apiStorageObject.PermissionWrite;
            var updateTime = apiStorageObject.UpdateTime;
            var userId = apiStorageObject.UserId;
            var version = apiStorageObject.Version;
            EventObject value = JsonUtility.FromJson<EventObject>(apiStorageObject.Value);
            print("Start: "+value.start);
            print("Stop: "+ value.stop);
            print("Category: "+ value.category);
            print("THIS IS THE TEST: "+collection + " " + creationTime + " " + key + " " + permissionRead + " " + permissionWrite + " " + updateTime + " " + userId + " " + version + " " + value);
        }
}
[System.Serializable]
public class EventObject
{
    public int start;
    public int stop;
    public int category;
}

```

---

<div class="post-metadata">

### Author: ![novabyte](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/novabyte/32/1324_2.png) [@novabyte](https://forum.heroiclabs.com/u/novabyte)
#### Post date: [May 21, 2020, 6:12pm UTC](https://forum.heroiclabs.com/t/parse-a-list-of-storage-objects-in-unity/727/5 "2020-05-21T18:12:51Z")

</div>

@EarthAdam I’m glad its sorted. I didn’t realize its not clear that the JSON value from a storage object in the Unity client comes back as a JSON string which you can then decode to your data model. We should add an example to the docs for it.

---

<div class="post-metadata">

### Author: ![EarthAdam](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/earthadam/32/259_2.png) [@EarthAdam](https://forum.heroiclabs.com/u/EarthAdam)
#### Post date: [May 21, 2020, 6:55pm UTC](https://forum.heroiclabs.com/t/parse-a-list-of-storage-objects-in-unity/727/6 "2020-05-21T18:55:27Z")

</div>

@novabyte I am not the sharpest on immediately knowing what to do with JSON data, so left to my own devices I start splitting the string at brackets and commas. Depending on how many other people are like me, having that in the docs would help!
