Page 1 of 1

Incorrect saving/loading of string (a URL) results in: FormatException: Expected '{' or "null", found '"'. When loading.

Posted: Tue Apr 20, 2021 10:04 pm
by ForemanDesigns
I am trying to use Easy Save to save a URL, and load it when the game is started. Very basic. I am using the latest version of Easy Save and the code given on this page: https://docs.moodkie.com/easy-save-3/getting-started/

However, I am getting an error.

Here is the input string (a URL for an avatar download): https://d1a370nemizbjq.cloudfront.net/2 ... 3c5b58.glb

Here is what gets saved in "SaveFile.es3":

{
"avatarUrl" : {
"__type" : "string",
"value" : "https:\/\/d1a370nemizbjq.cloudfront.net\/24c09e08-f879-4147-9b27-6b05473c5b58.glb"
}
}

When I try to load the string when the game starts, I get this error:

FormatException: Expected '{' or "null", found '"'.
ES3Internal.ES3JSONReader.ReadNullOrCharIgnoreWhitespace (System.Char expectedChar) (at Assets/Plugins/Easy Save 3/Scripts/Readers/ES3JSONReader.cs:357)
ES3Internal.ES3JSONReader.StartReadObject () (at Assets/Plugins/Easy Save 3/Scripts/Readers/ES3JSONReader.cs:111)
ES3Reader.ReadObject[T] (System.Object obj, ES3Types.ES3Type type) (at Assets/Plugins/Easy Save 3/Scripts/Readers/ES3Reader.cs:236)
ES3Reader.ReadInto[T] (System.Object obj, ES3Types.ES3Type type) (at Assets/Plugins/Easy Save 3/Scripts/Readers/ES3Reader.cs:292)
ES3Reader.ReadInto[T] (System.String key, T obj) (at Assets/Plugins/Easy Save 3/Scripts/Readers/ES3Reader.cs:228)
ES3.LoadInto[T] (System.String key, T obj, ES3Settings settings) (at Assets/Plugins/Easy Save 3/Scripts/ES3.cs:536)
ES3.LoadInto[T] (System.String key, T obj) (at Assets/Plugins/Easy Save 3/Scripts/ES3.cs:491)
GameManager.Awake () (at Assets/_Scripts/GameManager.cs:45)

Could you please advise in how to fix this?

Re: Incorrect saving/loading of string (a URL) results in: FormatException: Expected '{' or "null", found '"'. When load

Posted: Wed Apr 21, 2021 9:19 am
by Joel
Hi there,

I don't appear to be getting this error at my end. I tried to replicate this with the following code:

Code: Select all

using UnityEngine;

public class SaveURLTest : MonoBehaviour
{
    void Start()
    {
        ES3.Save("url", "https://d1a370nemizbjq.cloudfront.net/24c09e08-f879-4147-9b27-6b05473c5b58.glb");
        Debug.Log(ES3.Load<string>("url"));
    }
}
Please could you create a basic script which replicates it?

Also you appear to be using ES3.LoadInto, which should not be used for strings because they're immutable.

All the best,
Joel

Re: Incorrect saving/loading of string (a URL) results in: FormatException: Expected '{' or "null", found '"'. When load

Posted: Wed Apr 21, 2021 4:07 pm
by ForemanDesigns
Joel wrote: Wed Apr 21, 2021 9:19 am Hi there,

I don't appear to be getting this error at my end. I tried to replicate this with the following code:

Code: Select all

using UnityEngine;

public class SaveURLTest : MonoBehaviour
{
    void Start()
    {
        ES3.Save("url", "https://d1a370nemizbjq.cloudfront.net/24c09e08-f879-4147-9b27-6b05473c5b58.glb");
        Debug.Log(ES3.Load<string>("url"));
    }
}
Please could you create a basic script which replicates it?

Also you appear to be using ES3.LoadInto, which should not be used for strings because they're immutable.

All the best,
Joel
Joel,

Thank you for your reply! I missed the line in the documentation that said LoadInto shouldn't be used for strings - I think that was the issue. When I use ES3.Load<string>("avatarUrl") then things seem to work just fine.

I am curious about the JSON formatting for the URL, though. When I open SaveFile.es3 in a text editor, the url has an extra backlash for each forwardslash:

"value" : "https:\/\/d1a370nemizbjq.cloudfront.net\/2ec640ce-2ce9-4ec0-9033-26675d181338.glb"

Is this because of the way strings are serialized into JSON or something? When it's loaded, the extra backslashes don't come in.

Re: Incorrect saving/loading of string (a URL) results in: FormatException: Expected '{' or "null", found '"'. When load

Posted: Wed Apr 21, 2021 4:13 pm
by Joel
Hi there,

This is called character escaping, and is part of the JSON specification to ensure that strings don't break the formatting of the file.

All the best,
Joel

Re: Incorrect saving/loading of string (a URL) results in: FormatException: Expected '{' or "null", found '"'. When load

Posted: Sat Apr 24, 2021 9:52 pm
by ForemanDesigns
Joel wrote: Wed Apr 21, 2021 4:13 pm Hi there,

This is called character escaping, and is part of the JSON specification to ensure that strings don't break the formatting of the file.

All the best,
Joel
Great, thank you for the explanation, Joel! Much appreciated. :D