Android Google Quest reward data file. How do I wright it in C#?

Hi! I have been stuck on this for days now:/…

When a user has accomplished a Quest in Google Play Games they should get a reward. In the google play console they want me to upload a file/script that get executed when the reward should be delivered. As an example they suggest a Json string like this:

{
    "bonusGems": 2134,
    "extraSeconds": 12
}

more info here: Events  |  Play Games Services  |  Google for Developers

That doesnt help me much… I want to wright it in C# if possible, but how exactly should the script look like? Lets say I just want to increase the players “gems” by 10.

// Erik

Ok, after hours of searching and asking on forums, i found the answer.
This is the data text file that i submitted on the developer console:

{
“Gems” : 10
}

NOTE: This script is in a notepad document and is not c#, but you can use the value of gems, or whatever you want later…

Then in Unity in a C# script, you can get the value of whatever you set in the JSON script. This is how i did it:
(I assume you know how to do the script to receive a reward for the quest, but if not i will put it in anyway)

NOTE: Using JSONObject plugin from the asset store

How to get the value:

string reward = System.Text.Encoding.UTF8.GetString(quest.Milestone.CompletionRewardData);
    				JSONObject rewardJson = new JSONObject(reward);
    				int gems = int.Parse(rewardJson.GetField("Gems").ToString());

Using it in context:

private void ClaimMilestone(IQuestMilestone toClaim)
	{
		PlayGamesPlatform.Instance.Quests.ClaimMilestone(toClaim,
		                                                 (QuestClaimMilestoneStatus status, IQuest quest, IQuestMilestone milestone) => {
			if (status == QuestClaimMilestoneStatus.Success)
			{
				string reward = System.Text.Encoding.UTF8.GetString(quest.Milestone.CompletionRewardData);
				JSONObject rewardJson = new JSONObject(reward);
				int gems = int.Parse(rewardJson.GetField("Gems").ToString());
				PlayerPrefs.SetInt("Gems", PlayerPrefs.GetInt("Gems", 0) + gems);
			}
		});
	}

I hope this helps! I know i was terribly stuck on this, but it felt great to get it solved. If you need any help just comment and i’ll see if i can help you. (I hope i was clear in my answer, but if not, tell me!)

Here are some other forum questions i asked that you can look at aswell to help you:

Using variable from JSON

Another question relating