Microsoft Azure PlayFab logo
    • Multiplayer
    • LiveOps
    • Data & Analytics
    • Add-ons
    • For Any Role

      • Engineer
      • Designer
      • Executive
      • Marketer
    • For Any Stage

      • Build
      • Improve
      • Grow
    • For Any Size

      • Solo
      • Indie
      • AAA
  • Runs on PlayFab
  • Pricing
    • Blog
    • Forums
    • Contact us
  • Sign up
  • Sign in
  • Ask a question
  • Spaces
    • PlayStream
    • Feature Requests
    • Add-on Marketplace
    • Bugs
    • API and SDK Questions
    • General Discussion
    • LiveOps
    • Topics
    • Questions
    • Articles
    • Ideas
    • Users
    • Badges
  • Home /
  • General Discussion /
avatar image
Question by David Jones · Jun 19, 2019 at 01:49 AM · CloudScriptTitle Data

How to parse through title data in clouscript

Comment

People who like this

0 Show 2
10 |1200 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image David Jones · Jun 19, 2019 at 12:52 AM 0
Share

I accidentally clicked login and post before I actually wrote my question but i was hoping somebody could explain how to parse through my JSON files in cloudscript. I'm used to coding in C# in unity so javascript is a little foreign to me.

Lets say this was my title data could someone give me a way to pull out the ratingTop value so I can then compare it to another int?

"Settler": {
    "id": 1,
    "rating": 0,
    "ratingTop": 49
  },
  "Rebellious": {
    "id": 2,
    "rating": 50,
    "ratingTop": 99
  }
avatar image David Jones · Jun 19, 2019 at 01:46 AM 0
Share

A second question is how would I get the next key once they pass the "ratingTop"? For example thier rating is now 50 so they move on to the next Class which would be Rebellious. I understand how I could hardcode the name to save to playerdata(title) but there is going to be more than just 2 "levels" so is there a way to iterate to the next key in title data result?

1 Reply

· Add your reply
  • Sort: 
avatar image
Best Answer

Answer by Sarah Zhang · Jun 20, 2019 at 06:31 AM

Please refer to the following code.

var jsonString = {"Settler": {
 "id": 1,
 "rating": 0,
 "ratingTop": 49
 },
 "Rebellious": {
 "id": 2,
 "rating": 50,
 "ratingTop": 99
 }};

// Parse
var jsonObject = JSON.parse(jsonString);

//to pull out the ratingTop value
var ratingTop = jsonObject.ratingTop;

//to iterate to the next 
keyjsonObject.id = 3;
jsonObject.rating = 70;
jsonObject.ratingTop = 150;
var newJsonString = JSON.stringify(jsonObject); 
Comment
David Jones

People who like this

1 Show 2 · Share
10 |1200 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image David Jones · Jun 21, 2019 at 12:32 PM 0
Share

How would you differentiate the "settler" class from the "vigilante" class? I see how you pulled out ratingTop but should there be an extra line above that one? Im trying to check the current "class" of the player and see if they move up or not each time "rating" is awarded in game. But besides that this helped me pretty much build my function in cloudscript, thank you.

avatar image Sarah Zhang David Jones · Jul 13, 2019 at 12:47 PM 0
Share
// your json string
var jsonString = '{"Settler":{"id":1,"rating":0,"ratingTop":49},"Rebellious":{"id":2,"rating":50,"ratingTop":99}}';
    
// pares it into a json object
var jsonObj = JSON.parse(jsonString);
    
// get the value as a normal object
var ratingTop1 = jsonObj.Settler.ratingTop;
var ratingTop2 = jsonObj.Rebellious.ratingTop;
    
// iterate over the json object
// the 'key' is the property of the jsonObject
for(var key in jsonObj){
	console.log(key);
        // get the 'ratingTop' for each key
        console.log(jsonObj[key].ratingTop);
}

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Navigation

Spaces
  • General Discussion
  • API and SDK Questions
  • Feature Requests
  • PlayStream
  • Bugs
  • Add-on Marketplace
  • LiveOps
  • Follow this Question

    Answers Answers and Comments

    2 People are following this question.

    avatar image avatar image

    Related Questions

    Changing Title Data is not stable 1 Answer

    Data Encryption for Player Data and CloudScript responses 1 Answer

    ExecuteCloudScript FunctionResult frustration 3 Answers

    Cloning from one project to other 1 Answer

    Title data override in Experiments 1 Answer

    PlayFab

    • Multiplayer
    • LiveOps
    • Data & Analytics
    • Runs on PlayFab
    • Pricing

    Solutions

    • For Any Role

      • Engineer
      • Designer
      • Executive
      • Marketer
    • For Any Stage

      • Build
      • Improve
      • Grow
    • For Any Size

      • Solo
      • Indie
      • AAA

    Engineers

    • Documentation
    • Quickstarts
    • API Reference
    • SDKs
    • Usage Limits

    Resources

    • Forums
    • Contact us
    • Blog
    • Service Health
    • Terms of Service
    • Attribution

    Follow us

    • Facebook
    • Twitter
    • LinkedIn
    • YouTube
    • Sitemap
    • Contact Microsoft
    • Privacy & cookies
    • Terms of use
    • Trademarks
    • Safety & eco
    • About our ads
    • © Microsoft 2020
    • Anonymous
    • Sign in
    • Create
    • Ask a question
    • Create an article
    • Post an idea
    • Spaces
    • PlayStream
    • Feature Requests
    • Add-on Marketplace
    • Bugs
    • API and SDK Questions
    • General Discussion
    • LiveOps
    • Explore
    • Topics
    • Questions
    • Articles
    • Ideas
    • Users
    • Badges