Sign In Register

How can we help you today?

Start a new topic
Answered

Retrieving Data From List?

Hi, I am not super familiar with parsing JSON data. I have been able to use .GetString and .GetData, however I have recently created a list of data in GameSparks and am having trouble retrieving it in Unity.


My data is saved with this Cloud Code:

   

 

playerPurchasesList.update({"_id":{"$oid":playerPurchases._id.$oid}}, {$set:{"subscribed" : {"expirationDate" : purchasedItem, "device" : "IOS"}}});

  


The Data looks like this in the Data explorer:

  

 subscribed:
           expirationDate: "1/31/2019 11:41:40 PM"
           device: "IOS"

  

When I try to access the data in Unity with these two attempts, I am getting null.


 

response.ScriptData.GetGSData("player_Purchase_Data").GetGSDataList("subscribed")

  

response.ScriptData.GetGSData("player_Purchase_Data").GetStringList("subscribed")

 

I am tired and going to bed. I imagine this is an easy solution that I will be able to figure out tomorrow, however if anyone knows how to access this data, and is willing to explain, you would make my morning =).


Thanks, Ian.


Best Answer

Hey Ian,


As subscribed is another object, you would need to use .GetGSData again.

 

This would retrieve the object so that you can access its children using .getString("expirationData"), etc.

response.ScriptData.GetGSData("player_Purchase_Data").GetGSData("subscribed")

.getStringList would need to be retrieving an array of string, .getGSDataList would need to retrieve an array of objects.


Hope this helps.


Still having trouble with this. How do I reference nested data? I can .getString() for data that is on the root of the GSObject but cannot seem to access the data that is nested. 

 _id:
         $oid: "5c4c8259face9a0505237dc0"
 spiritGuidesMeditation: "1549000153605"
 shamanJourney: "1549000153791"
 subscribed:
         expirationDate: "2/1/2019 3:01:54 PM"
         device: "IOS"

 

I can access the spiritGuidesMeditation and shamanJourney with .getString() but when I try to access expirationDate and device by using .getStringList("subscribed") I get null...

Hi,

Can you copy/past all of your cloud code please?
Do you have a null on response.ScripData.GetString("_id") ?
I think that you forgot to set your scriptData in your cloud code...
Example: Spark.setScriptData("playerPurchasesList", playerPurchasesList);
Then in Unity :
List<GSData> gsDataPlayerPurchasesList = response.ScriptData.GetGSDataList("playerPurchasesList");

Rgds

 

Answer

Hey Ian,


As subscribed is another object, you would need to use .GetGSData again.

 

This would retrieve the object so that you can access its children using .getString("expirationData"), etc.

response.ScriptData.GetGSData("player_Purchase_Data").GetGSData("subscribed")

.getStringList would need to be retrieving an array of string, .getGSDataList would need to retrieve an array of objects.


Hope this helps.


1 person likes this

@Chase Wilksch


Christ I feel dumb, that makes perfect sense. Thank you Chase, this worked.


Thanks for the replies Chase and barudy! I appreciate your time.


Ian

Login to post a comment