question

Nishal John avatar image
Nishal John asked

Unable to access The JSON data in Title Data

6295-image.png

I have the above JSON stored in my Title Data under the Key: BugDataArray.

I'm using a cloud function to access this data. After accessing said data I want to add a new data to the array and use Set title data to save the data again. I attempted it and it did not work so I tested in small scale to simply see if I could access the "bloo" key to get the array and save to to another "title data field" (just as a test)

However every time I attempt to read the value "bloo" the value never gets saved. Below is the code. I'm not sure whats wrong, since I'm quite clueless on how I can log the errors to playfab.

6302-image.png

I'm sure I am doing something wrong but I dont know what, this seems quite straightforward. Any help is appreciated.

Title Dataunreal
image.png (10.8 KiB)
image.png (12.8 KiB)
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
Rick Chen avatar image
Rick Chen answered

It looks like there is an issue with the way you are accessing the key from the object. The object is a string representation of the JSON data stored in the title data. To access the key, you need to first parse the string as a JSON object using the method "JSON.parse()". Then you can access the key from the parsed object and its value (an array) is assigned to the variable. After that you can use the method "JSON.stringify()"to stringify the variable and save it to the title data. The following code is an example.

 handlers.updateBugReportData= function(args){
     var titleData = server.GetTitleData({
         keys: ["BugDataArray"]
     });
       
      var bugDataReport = JSON.parse(titleData.Data["BugDataArray"]);
         
     server.SetTitleData({
         key: "BugReport",
         value:  JSON.stringify(bugDataReport.bloo)
     });
 }

Hope this can help you.

1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Nishal John avatar image Nishal John commented ·

That was the issue, its was my mistake for thinking it got sent as an existing JSON and for attempting to save the value without first making it a string. Thank you!

0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.