1

I have added Google play games services to my android app in Unity3d. I am trying to add quests, but am having issues claiming the reward. In the developer console, i have uploaded this reward data file:

{ "Coins" : 10 }

In Unity, I am accessing this by using

System.Text.Encoding.UTF8.GetString(quest.Milestone.CompletionRewardData)

Which returns: { "Coins" : 10 }

My question is, how do i then turn the variable coins into a c# variable for use in my app?

Any help is greatly appreciated, thanks.

Alex Boullé
  • 431
  • 5
  • 17
  • Use NewtonSoft JSON library for parsing json data. It is very easy to use for parsing complex data. Check this link http://stackoverflow.com/questions/6620165/how-can-i-parse-json-with-c – Sandy Oct 29 '15 at 10:04
  • I'm confused. Could you maybe write a bit of code showing how to do it? All i need to get is the value of coins. Thanks @Sandy – Alex Boullé Oct 29 '15 at 10:07

1 Answers1

2

We're using JSONObject in Unity to create and parse JSON, it's quite easy to use.

string reward = "{ \"Coins\" : 10 }";

JSONObject rewardJSON = new JSONObject(reward);
int coins = int.Parse(rewardJSON.GetField("Coins").ToString());
dabo248
  • 3,367
  • 4
  • 27
  • 37