FormatException: File is not valid JSON

Discussion and help for Easy Save 3
Post Reply
ponytest
Posts: 2
Joined: Mon Jan 06, 2020 1:56 pm

FormatException: File is not valid JSON

Post by ponytest »

FormatException: File is not valid JSON. Expected '{' at beginning of file, but found '
ES3Internal.ES3JSONReader.SkipOpeningBraceOfFile () (at Assets/Plugins/Easy Save 3/Scripts/Readers/ES3JSONReader.cs:474)

Below is the code:

Code: Select all

public class SaveMgr
{
    static public void LoadData()
    {
        Data.IsTip = ES3.Load("Tip", Data.SaveDataPath, true);
        Data.IsCompleted = ES3.Load("Complete", Data.SaveDataPath, false);
        Data.CurrentID = ES3.Load("CurrentID", Data.SaveDataPath, 1);
        Data.HighestID = ES3.Load("HighestID", Data.SaveDataPath, 1);
        SoundMgr.Inst.audioSource.volume = ES3.Load("SoundValue", Data.SaveDataPath, 1.0f);
    }

    static public void SaveData()
    {
        ES3.Save<bool>("Tip", Data.IsTip, Data.SaveDataPath);
        ES3.Save<bool>("Complete", Data.IsCompleted, Data.SaveDataPath);
        ES3.Save<int>("CurrentID", Data.CurrentID, Data.SaveDataPath);
        ES3.Save<int>("HighestID", Data.HighestID, Data.SaveDataPath);
        ES3.Save<float>("SoundValue", SoundMgr.Inst.audioSource.volume, Data.SaveDataPath);
    }
}
     static public string SaveDataPath = Application.dataPath + "/Save/SaveData";
save file download:https://www.lanzous.com/i8i3fhg

The user encountered this problem and gave me this archive.
Can I view the data in savadata? I tried to open it with the TXT document and it was empty.
Please tell me what data is in savadata

My English is not good. It ’s all translated by Google. I hope you understand.
User avatar
Joel
Moodkie Staff
Posts: 4849
Joined: Wed Nov 07, 2012 10:32 pm

Re: FormatException: File is not valid JSON

Post by Joel »

Hi there,

The save file your customer has sent you is empty, which is why you are getting the error message. This most commonly happens because the file is in a folder which is automatically stored to cloud, but the contents of the file have not been downloaded from the cloud.

It might also happen if there is not enough space in their harddrive to store the data, but an exception would be thrown when saving if this was the case.

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
ponytest
Posts: 2
Joined: Mon Jan 06, 2020 1:56 pm

Re: FormatException: File is not valid JSON

Post by ponytest »

Joel wrote:Hi there,

The save file your customer has sent you is empty, which is why you are getting the error message. This most commonly happens because the file is in a folder which is automatically stored to cloud, but the contents of the file have not been downloaded from the cloud.

It might also happen if there is not enough space in their harddrive to store the data, but an exception would be thrown when saving if this was the case.

All the best,
Joel
Thank you for your reply

Code: Select all

static public void SaveData()
    {
        ES3.Save<bool>("Tip", Data.IsTip, Data.SaveDataPath);
        ES3.Save<bool>("Complete", Data.IsCompleted, Data.SaveDataPath);
        ES3.Save<int>("CurrentID", Data.CurrentID, Data.SaveDataPath);
        ES3.Save<int>("HighestID", Data.HighestID, Data.SaveDataPath);
        ES3.Save<float>("SoundValue", SoundMgr.Inst.audioSource.volume, Data.SaveDataPath);
    }
}
1.According to you, if I keep them separately one by one, will it reduce the occurrence of a problem? Do you have a better suggestion? For example, recommend some apis.
2.How can I judge whether the archive is empty (broken) so that I can repair the archives of those users
User avatar
Joel
Moodkie Staff
Posts: 4849
Joined: Wed Nov 07, 2012 10:32 pm

Re: FormatException: File is not valid JSON

Post by Joel »

Hi there,

This issue does not occur at our end but instead will occur at the customers end, so it's not something that we would be able to prevent.

The best way to detect the issue is simply to catch the InvalidDataException. If you want to be certain that it's because of corrupt data, you can use ES3.LoadRawString to get the contents of the file and check that it's not null.

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
Post Reply