How to save Json file on Google Game Services

Hello community I am trying to save on the cloud what could be the best way to save a Json file in the cloud?
The Json file code that I am wishing to save

 void Save_player_data()
    {
        player_data = new Player_data()
        {
            gold = DataController.instance.gold,
            cash = DataController.instance.cash,
            boost_value = TimeManager.instance.current_boostValue_gameplay,
            ad_info = in_app_manager.banner_ad
        };
        string json = JsonUtility.ToJson(player_data,true);
        File.WriteAllText(Application.persistentDataPath + "/player_data.json", json);
    }


public void Load_player_data()
    {
        string save_string = File.ReadAllText(Application.persistentDataPath + "/player_data.json");
        player_data = JsonUtility.FromJson<Player_data>(save_string);
        if (File.Exists(Application.persistentDataPath + "/player_data.json"))
        {
            DataController.instance.gold = player_data.gold;
            DataController.instance.cash = player_data.cash;
            TimeManager.instance.current_boostValue_gameplay = player_data.boost_value;
            in_app_manager.banner_ad = player_data.ad_info;
        }
        else return;
    }

And the class which I am wishing to use

    public void LoadFromCloud(Action<string> afterLoadAction)
    {
        if (isAuthenticated && !isProcessing)
        {
            StartCoroutine(LoadFromCloudRoutin(afterLoadAction));
        }
        else
        {
            Login();
        }
    }
public void SaveToCloud(string dataToSave)
    {

        if (isAuthenticated)
        {
            loadedData = dataToSave;
            isProcessing = true;
            ((PlayGamesPlatform)Social.Active).SavedGame.OpenWithAutomaticConflictResolution(m_saveFileName, DataSource.ReadCacheOrNetwork, ConflictResolutionStrategy.UseLongestPlaytime, OnFileOpenToSave);
        }
        else
        {
            Login();
        }
    }

There’s rather more to it than what you have in your scripts.

I used and adapted the example given here http://answers.unity.com/answers/1234420/view.html in the reply given by C4nDiM4n to get it working in my app earlier this year.

Hello what should be the way to save Json file there?

In the example, the saveString field would contain the data that is to be saved. On line 88 the ToBytes() function is called, which converts the contents of saveString to a byte array, and then passes that to the cloud save function.

You just need to pass in your Json string instead.

the LoadFromCloud method and SaveToCloud method? But the value passing to LoadFromCloud method is action

The LoadFromCloud() method in the example I linked doesn’t take any parameters.

Have you incorporated the linked example into your own app so you can see how the it works? Once you do that you should be able to adapt it to your own needs.

Sorry I looked for another code, so basically if I want to save I need to save my Json Files which are six of them as a string array, convert to a byte array to save and to load convert a bite array to string array then replace it with the save file that exists?

Yes that’s pretty much it.

1 Like

thank you very much for your help I wanna work it now good luck

1 Like