Load List --> System.FormatException: Expected '{' or "null", found '1'

Discussion and help for Easy Save 3
wyliam
Posts: 6
Joined: Tue Feb 04, 2014 3:14 am

Load List --> System.FormatException: Expected '{' or "null", found '1'

Post by wyliam »

On Easy Save 3.3.2 I'm attempting to load a saved list of structs (Setting) that a few generic types in them (int, enum, string & 2 objects).
I can save the file successfully in script, and even open/view it on disk. However, loading it back into the list seems to push an error. Any help on what this is so I can track it down?

Loading it is done as such:

Code: Select all

List<Setting> s = ES3.Load("_ProfileSettings_", fileName, new List<Setting>());

Code: Select all

[5] System.FormatException: Expected '{' or "null", found '1'.
  at ES3Internal.ES3JSONReader.ReadNullOrCharIgnoreWhitespace (System.Char expectedChar) [0x00083] in X:\Perforce\wyliam_FAAHHX\Conquest\Assets\Plugins\Easy Save 3\Scripts\Readers\ES3JSONReader.cs:357 
  at ES3Internal.ES3JSONReader.StartReadObject () [0x00008] in X:\Perforce\wyliam_FAAHHX\Conquest\Assets\Plugins\Easy Save 3\Scripts\Readers\ES3JSONReader.cs:111 
  at ES3Reader.ReadObject[T] (ES3Types.ES3Type type) [0x00001] in X:\Perforce\wyliam_FAAHHX\Conquest\Assets\Plugins\Easy Save 3\Scripts\Readers\ES3Reader.cs:246 
  at ES3Reader.Read[T] (ES3Types.ES3Type type) [0x0008a] in X:\Perforce\wyliam_FAAHHX\Conquest\Assets\Plugins\Easy Save 3\Scripts\Readers\ES3Reader.cs:278 
  at ES3Reader.Read[T] () [0x00001] in X:\Perforce\wyliam_FAAHHX\Conquest\Assets\Plugins\Easy Save 3\Scripts\Readers\ES3Reader.cs:126 
  at ES3Types.ES3Type_Setting.Read[T] (ES3Reader reader) [0x00093] in X:\Perforce\wyliam_FAAHHX\Conquest\Assets\Easy Save 3\Types\ES3Type_Setting.cs:47 
  at ES3Reader.ReadObject[T] (ES3Types.ES3Type type) [0x00017] in X:\Perforce\wyliam_FAAHHX\Conquest\Assets\Plugins\Easy Save 3\Scripts\Readers\ES3Reader.cs:249 
  at ES3Reader.Read[T] (ES3Types.ES3Type type) [0x0008a] in X:\Perforce\wyliam_FAAHHX\Conquest\Assets\Plugins\Easy Save 3\Scripts\Readers\ES3Reader.cs:278 
  at ES3Types.ES3ListType.Read (ES3Reader reader) [0x00032] in X:\Perforce\wyliam_FAAHHX\Conquest\Assets\Plugins\Easy Save 3\Scripts\Types\Collection Types\ES3ListType.cs:64 
  at ES3Reader.Read[T] (ES3Types.ES3Type type) [0x00056] in X:\Perforce\wyliam_FAAHHX\Conquest\Assets\Plugins\Easy Save 3\Scripts\Readers\ES3Reader.cs:274 
  at ES3Reader.Read[T] (System.String key, T defaultValue) [0x0001a] in X:\Perforce\wyliam_FAAHHX\Conquest\Assets\Plugins\Easy Save 3\Scripts\Readers\ES3Reader.cs:212 
  at ES3.Load[T] (System.String key, T defaultValue, ES3Settings settings) [0x00032] in X:\Perforce\wyliam_FAAHHX\Conquest\Assets\Plugins\Easy Save 3\Scripts\ES3.cs:419 
  at ES3.Load[T] (System.String key, System.String filePath, T defaultValue) [0x00001] in X:\Perforce\wyliam_FAAHHX\Conquest\Assets\Plugins\Easy Save 3\Scripts\ES3.cs:391 
  at Pinbox.ProfileSettings.TryLoad (System.String fileName, System.Collections.Generic.List`1[Pinbox.Setting]& setting) [0x00002] in X:\Perforce\wyliam_FAAHHX\Conquest\Assets\_\02_Scripts\Profile\ProfileSettings.cs:115 	
User avatar
Joel
Moodkie Staff
Posts: 4826
Joined: Wed Nov 07, 2012 10:32 pm

Re: Load List --> System.FormatException: Expected '{' or "null", found '1'

Post by Joel »

Hi there,

It's not possible for me to tell what is happening from what you've posted. Please could you try deleting your save data by going to Tools > Easy Save 3 > Clear persistent data path?

If that doesn't resolve the issue, please could you show me the code you're using to save? And just to check, have you changed anything in the Easy Save Settings or Types window?

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
wyliam
Posts: 6
Joined: Tue Feb 04, 2014 3:14 am

Re: Load List --> System.FormatException: Expected '{' or "null", found '1'

Post by wyliam »

I cleared the path but no luck.
I haven't modified the settings/types other than to add types.

Here's the struct I filled the list with initially.

Code: Select all

static List<Setting> _settings = new List<Setting>();

    [Serializable]
    public struct Setting {
        public int ID;
        public SettingType category; // enum
        public string locKey;
        public object value;
        public object maxValue;
    }
I save the default values out to its own file. I can open/view this and it looks correct.

Code: Select all

public static bool TrySave() {
            string file = SettingsManager.PERSISTENT_SAVE_PATH + SettingsManager.PROFILEDATA_ + "Default.set";
            try {
                ES3.Save<List<Setting>>("_ProfileSettings_", _settings, file);
                return true;

            } catch (Exception e) {
                Debug.LogSevere(log, $"Save Failed!", e);
            }
            return false;
        }
The outputted file looks like this:

Code: Select all

{
	"_ProfileSettings_": {
		"__type": "System.Collections.Generic.List`1[[Pinbox.Setting, Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null]],mscorlib",
		"value": [
			{
				"ID": 100,
				"category": 1,
				"locKey": "Master",
				"value": 100,
				"maxValue": null
			},
			{
				"ID": 110,
				"category": 1,
				"locKey": "Music",
				"value": 100,
				"maxValue": null
			},
			{
				"ID": 120,
				"category": 1,
				"locKey": "Soundeffects",
				"value": 100,
				"maxValue": null
			},
			// (and so on)
			
I Load the file back in here.

Code: Select all

        static bool TryLoad(string fileName, out List<Setting> setting) {
            try {
            
                List<Setting> s = ES3.Load("_ProfileSettings_", fileName, new List<Setting>());

                setting = s;

                return true;

            } catch (Exception e) {
                Debug.LogSevere(log, $"Load failed -- {fileName}", e);
                setting = null;
            }

            return false;
        }
User avatar
Joel
Moodkie Staff
Posts: 4826
Joined: Wed Nov 07, 2012 10:32 pm

Re: Load List --> System.FormatException: Expected '{' or "null", found '1'

Post by Joel »

Hi there,

Please could you show me the ES3Type file created for your Setting class? This can be found at Easy Save 3/Types/ES3UserType_Setting.cs.

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
wyliam
Posts: 6
Joined: Tue Feb 04, 2014 3:14 am

Re: Load List --> System.FormatException: Expected '{' or "null", found '1'

Post by wyliam »

It looks like its in it's default directory than the others I've created and moved (and load fine).

Code: Select all

using System;
using UnityEngine;

namespace ES3Types
{
	[UnityEngine.Scripting.Preserve]
	[ES3PropertiesAttribute("ID", "category", "locKey", "value", "maxValue")]
	public class ES3Type_Setting : ES3Type
	{
		public static ES3Type Instance = null;

		public ES3Type_Setting() : base(typeof(Pinbox.Setting))
		{
			Instance = this;
		}

		public override void Write(object obj, ES3Writer writer)
		{
			var instance = (Pinbox.Setting)obj;
			
			writer.WriteProperty("ID", instance.ID, ES3Type_int.Instance);
			writer.WriteProperty("category", instance.category);
			writer.WriteProperty("locKey", instance.locKey, ES3Type_string.Instance);
			writer.WriteProperty("value", instance.value);
			writer.WriteProperty("maxValue", instance.maxValue);
		}

		public override object Read<T>(ES3Reader reader)
		{
			var instance = new Pinbox.Setting();
			string propertyName;
			while((propertyName = reader.ReadPropertyName()) != null)
			{
				switch(propertyName)
				{
					
					case "ID":
						instance.ID = reader.Read<System.Int32>(ES3Type_int.Instance);
						break;
					case "category":
						instance.category = reader.Read<Pinbox.SettingType>();
						break;
					case "locKey":
						instance.locKey = reader.Read<System.String>(ES3Type_string.Instance);
						break;
					case "value":
						instance.value = reader.Read<System.Object>();
						break;
					case "maxValue":
						instance.maxValue = reader.Read<System.Object>();
						break;
					default:
						reader.Skip();
						break;
				}
			}
			return instance;
		}
	}

	public class ES3Type_SettingArray : ES3ArrayType
	{
		public static ES3Type Instance;

		public ES3Type_SettingArray() : base(typeof(Pinbox.Setting[]), ES3Type_Setting.Instance)
		{
			Instance = this;
		}
	}
}
Attachments
Easy Save 3_Types.jpg
Easy Save 3_Types.jpg (106.99 KiB) Viewed 2947 times
User avatar
Joel
Moodkie Staff
Posts: 4826
Joined: Wed Nov 07, 2012 10:32 pm

Re: Load List --> System.FormatException: Expected '{' or "null", found '1'

Post by Joel »

Hi there,

Thanks for sending that over, I've managed to replicate the issue. Because the underlying types of your 'value' and 'maxValue' fields are primitives, but the field is declared as an 'object', it's not possible to resolve the data when loading using an ES3Type.

In this case the easiest solution is simply allow Easy Save to deserialise it automatically, rather than adding static support for it from the Types window.

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
wyliam
Posts: 6
Joined: Tue Feb 04, 2014 3:14 am

Re: Load List --> System.FormatException: Expected '{' or "null", found '1'

Post by wyliam »

Great! Super appreciate it. :)
wyliam
Posts: 6
Joined: Tue Feb 04, 2014 3:14 am

Re: Load List --> System.FormatException: Expected '{' or "null", found '1'

Post by wyliam »

Can you expand on how I'd go about doing that using EasySave's deserialization? Should I repopulate the struct after loading it in?
User avatar
Joel
Moodkie Staff
Posts: 4826
Joined: Wed Nov 07, 2012 10:32 pm

Re: Load List --> System.FormatException: Expected '{' or "null", found '1'

Post by Joel »

Hi there,

You would simply do what you're doing at the moment, but remove the ES3Type you've created from the Types panel. Once you remove the ES3Type, Easy Save will use it's own automatic serialization to serialize and deserialize the data.

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
LewyT
Posts: 3
Joined: Wed May 31, 2023 12:11 pm

Re: Load List --> System.FormatException: Expected '{' or "null", found '1'

Post by LewyT »

Hi, I get this same error even though I have not created any ES3Type (that I am aware of)
I have selected reset to default but I still get the error sometimes on Load.
Post Reply