FormatException: Expected quotation mark, found ','.

Discussion and help for Easy Save 3

FormatException: Expected quotation mark, found ','.

Postby ConnorG » Wed Aug 21, 2019 5:05 am

HI all,
Im trying to create a list of user login details and I got it to save them just fine but when I try to load them in i get this error:
FormatException: Expected quotation mark, found ','.
ES3Internal.ES3JSONReader.ReadQuotationMarkOrNullIgnoreWhitespace () (at Assets/Plugins/Easy Save 3/Scripts/Readers/ES3JSONReader.cs:428)
ES3Internal.ES3JSONReader.Read_string () (at Assets/Plugins/Easy Save 3/Scripts/Readers/ES3JSONReader.cs:530)
ES3Types.ES3Type_string.Read[T] (ES3Reader reader) (at Assets/Plugins/Easy Save 3/Scripts/Types/Primitive Types/ES3Type_string.cs:24)
ES3Reader.Read[T] (ES3Types.ES3Type type) (at Assets/Plugins/Easy Save 3/Scripts/Readers/ES3Reader.cs:238)
ES3Reader.Read[T] () (at Assets/Plugins/Easy Save 3/Scripts/Readers/ES3Reader.cs:98)
ES3Types.ES3Type_PaintUserProfile.ReadObject[T] (ES3Reader reader) (at Assets/Easy Save 3/Types/ES3Type_PaintUserProfile.cs:46)
ES3Types.ES3ObjectType.Read[T] (ES3Reader reader) (at Assets/Plugins/Easy Save 3/Scripts/Types/ES3ObjectType.cs:41)
ES3Reader.ReadObject[T] (ES3Types.ES3Type type) (at Assets/Plugins/Easy Save 3/Scripts/Readers/ES3Reader.cs:215)
ES3Reader.Read[T] (ES3Types.ES3Type type) (at Assets/Plugins/Easy Save 3/Scripts/Readers/ES3Reader.cs:244)
ES3Types.ES3ListType.Read (ES3Reader reader) (at Assets/Plugins/Easy Save 3/Scripts/Types/Collection Types/ES3ListType.cs:62)
ES3Reader.Read[T] (ES3Types.ES3Type type) (at Assets/Plugins/Easy Save 3/Scripts/Readers/ES3Reader.cs:240)
ES3Reader.Read[T] (System.String key) (at Assets/Plugins/Easy Save 3/Scripts/Readers/ES3Reader.cs:162)
ES3.Load[T] (System.String key, ES3Settings settings) (at Assets/Plugins/Easy Save 3/Scripts/ES3.cs:269)
ES3.Load[T] (System.String key) (at Assets/Plugins/Easy Save 3/Scripts/ES3.cs:240)
LoginManagerScript.Start () (at Assets/_Scripts/LoginManagerScript.cs:28)


Here is my code Nothing too fancy:
Code: Select all
[Serializable]
public class PaintUserProfile
{
    public string ProfileUsername;
    public string ProfilePassword;

    public PaintUserProfile(string us, string pw)
    {
        ProfileUsername = us;
        ProfilePassword = pw;
    }
}
public class LoginManagerScript : MonoBehaviour
{
    public Text username;
    public Text Password;
    public List<PaintUserProfile> Profiles;
    // Start is called before the first frame update
    void Start()
    {

        Profiles = ES3.Load<List<PaintUserProfile>>("myKey");//new List<PaintUserProfile>();
        //transform.position = ES3.Load<Vector3>("myPosition", Vector3.zero);
        //PaintUserProfile p1 = new PaintUserProfile("Admin", "pw");

        //Profiles.Add(p1);
        //ES3.Save<List<PaintUserProfile>>("myKey", Profiles,"Profiles.es3");

       


    }


Some help on how to fix this would be great :)
ConnorG
 
Posts: 3
Joined: Wed Aug 21, 2019 5:01 am

Re: FormatException: Expected quotation mark, found ','.

Postby Joel » Wed Aug 21, 2019 5:58 am

Hi there,

You specify a filename when you save, but not when you load. This means you're saving to a different file than you're loading from. Try specifying the filename when you load your data.

If this doesn't fix your issue, please could you PM me a project and instructions to replicate it?

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

Re: FormatException: Expected quotation mark, found ','.

Postby ConnorG » Wed Aug 21, 2019 6:47 am

silly question but I cant seem to find much info on how to do this. Can you send me an example?
ConnorG
 
Posts: 3
Joined: Wed Aug 21, 2019 5:01 am

Re: FormatException: Expected quotation mark, found ','.

Postby Joel » Wed Aug 21, 2019 7:13 am

Hi there,

No problem :) In the commented code (which I assume represents how you're saving your data), you specify the filePath parameter. I.e.

ES3.Save<List<PaintUserProfile>>("myKey", Profiles,"Profiles.es3");

So you should also specify the filePath parameter when loading. I.e:

Profiles = ES3.Load<List<PaintUserProfile>>("myKey", "Profiles.es3");

You can find more info on paths/filenames here:
https://docs.moodkie.com/easy-save-3/es ... locations/
All the best,
Joel
Joel Tebbett @ Moodkie Interactive
Twitter - Unity - LinkedIn
User avatar
Joel
Moodkie Staff
 
Posts: 2476
Joined: Wed Nov 07, 2012 10:32 pm

Re: FormatException: Expected quotation mark, found ','.

Postby ConnorG » Wed Aug 21, 2019 10:13 pm

Still not working :(
Here is my type script and load/save script

Code: Select all
using System;
using UnityEngine;

namespace ES3Types
{
   [UnityEngine.Scripting.Preserve]
   [ES3PropertiesAttribute("ProfileUsername", "ProfilePassword")]
   public class ES3Type_PaintUserProfile : ES3ObjectType
   {
      public static ES3Type Instance = null;

      public ES3Type_PaintUserProfile() : base(typeof(PaintUserProfile)){ Instance = this; }

      protected override void WriteObject(object obj, ES3Writer writer)
      {
         var instance = (PaintUserProfile)obj;
         
         writer.WriteProperty("ProfileUsername", instance.ProfileUsername, ES3Type_string.Instance);
         writer.WriteProperty("ProfilePassword", instance.ProfilePassword, ES3Type_string.Instance);
      }

      protected override void ReadObject<T>(ES3Reader reader, object obj)
      {
         var instance = (PaintUserProfile)obj;
         foreach(string propertyName in reader.Properties)
         {
            switch(propertyName)
            {
               
               case "ProfileUsername":
                  instance.ProfileUsername = reader.Read<System.String>(ES3Type_string.Instance);
                  break;
               case "ProfilePassword":
                  instance.ProfilePassword = reader.Read<System.String>(ES3Type_string.Instance);
                  break;
               default:
                  reader.Skip();
                  break;
            }
         }
      }

      protected override object ReadObject<T>(ES3Reader reader)
      {
            string ProfileUsername = reader.Read<string>();
            string ProfilePassword = reader.Read<string>();
            var instance = new PaintUserProfile(ProfileUsername,ProfilePassword);
         ReadObject<T>(reader, instance);
         return instance;
      }
   }

   public class ES3Type_PaintUserProfileArray : ES3ArrayType
   {
      public static ES3Type Instance;

      public ES3Type_PaintUserProfileArray() : base(typeof(PaintUserProfile[]), ES3Type_PaintUserProfile.Instance)
      {
         Instance = this;
      }
   }
}



Code: Select all
using System.Collections;
using System.Collections.Generic;
using System;
using UnityEngine;
using UnityEngine.UI;
using ES3Internal;
[Serializable]
public class PaintUserProfile
{
    public string ProfileUsername;
    public string ProfilePassword;

    public PaintUserProfile(string us, string pw)
    {
        ProfileUsername = us;
        ProfilePassword = pw;
    }
}
public class LoginManagerScript : MonoBehaviour
{
    public Text username;
    public Text Password;
    public List<PaintUserProfile> Profiles;
    // Start is called before the first frame update
    void Start()
    {

        //Profiles = ES3.Load<List<PaintUserProfile>>("myKey","Profiles.es3");//new List<PaintUserProfile>();
        //Profiles = ES3.Load<List<PaintUserProfile>>("myUsers", "MySaves/Profiles.es3");
        PaintUserProfile p1 = new PaintUserProfile("Admin", "pw");

        Profiles.Add(p1);
        ES3.Save<List<PaintUserProfile>>("myUsers", Profiles, "MySaves/Profiles.es3");




    }

    // Update is called once per frame
    void Update()
    {
       
    }
}



This is causing me grief as i cant seem to google this problem :P
ConnorG
 
Posts: 3
Joined: Wed Aug 21, 2019 5:01 am

Re: FormatException: Expected quotation mark, found ','.

Postby Joel » Thu Aug 22, 2019 7:56 am

Hi Connor,

The modifications you've made to your ES3Type are incorrect. In your ReadObject method you are using reader.Read<string>() to read your data:

protected override object ReadObject<T>(ES3Reader reader)
{
string ProfileUsername = reader.Read<string>();
string ProfilePassword = reader.Read<string>();
var instance = new PaintUserProfile(ProfileUsername,ProfilePassword);
ReadObject<T>(reader, instance);
return instance;
}


This does not read the property name and type, which will cause your error. You should use ReadProperty instead, or use a try/catch statement like in the other ReadObject method. If you are doing this, you also shouldn't call ReadObject<T> at the end, because you've already read the data.

However, there's likely an easier way. Unless your PaintUserProfile immediately does anything with the username and password, you should just be able to set these to blank strings, and then call ReadObject. i.e.

protected override object ReadObject<T>(ES3Reader reader)
{
var instance = new PaintUserProfile("","");
ReadObject<T>(reader, instance);
return instance;
}


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


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 3 guests

cron