FormatException

Discussion and help for Easy Save 3

FormatException

Postby Gnarwi » Wed Aug 14, 2019 10:10 pm

Im trying to save a simple List<int> but it keeps throwing this exception when im trying to load it : [*]FormatException: Expected '}', found '0'.[/*]
Am i missing something obvious here?

Here are my Save / Load methods. Load() is being called on Start() and Save() is on OnApplicationQuit().


Code: Select all
    public void Save()
    {
        List<int> ids = new List<int>();

        for (int i = 0; i < items.Count; i++)
        {
            ids.Add(items[i].id);
        }

        ES3.Save<List<int>>("Inventory", ids);
     
    }


Code: Select all
    public void Load()
    {

        List<int> ids = new List<int>();

        if (ES3.FileExists())
        {
            if (ES3.KeyExists("Inventory"))
            {

                ES3.LoadInto<List<int>>("Inventory", ids);

            }
           
        }

    }


And here is what it outputs. Seems to save just fine?

Code: Select all
{"Inventory":{"__type":"System.Collections.Generic.List`1[[System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]],mscorlib","value":[0,2,1]}}
Gnarwi
 
Posts: 2
Joined: Wed Aug 14, 2019 9:53 pm

Re: FormatException

Postby Joel » Thu Aug 15, 2019 8:59 am

Hi there,

You need to use ES3.Load rather than ES3.LoadInto. I.e.

ids = ES3.Load<List<int>>("Inventory");

ES3.LoadInto is for loading data into existing objects. As your list contains value types, this is not possible. In your case, as you've provided an empty List as a parameter, Easy Save expects an empty List in the data. Instead it finds an integer, triggering a FormatException.

All the best,
Joel
Joel Tebbett @ Moodkie Interactive
Twitter - Unity - LinkedIn
User avatar
Joel
Moodkie Staff
 
Posts: 2477
Joined: Wed Nov 07, 2012 10:32 pm

Re: FormatException

Postby Gnarwi » Thu Aug 15, 2019 9:41 am

That solved it.

Thanks for your help.
Gnarwi
 
Posts: 2
Joined: Wed Aug 14, 2019 9:53 pm


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 3 guests