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 /
  • API and SDK Questions /
avatar image
Question by kesyas · Apr 24, 2020 at 02:56 AM ·

how can i access json value??

In C # code,

I want to know how to access a deeper json key.

I want to access the loginstreak key. Is my code above correct?

result.Data ["CheckInTracker"].Value

I know that this is the first approach.

Because that value is a string so The parse process seems to be necessary. Is that right??

How to access deep json key with parses variable after that?

acess.png (27.0 kB)
accccc.png (26.5 kB)
Comment

People who like this

0 Show 0
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

3 Replies

· Add your reply
  • Sort: 
avatar image
Best Answer

Answer by Sarah Zhang · May 04, 2020 at 03:10 AM

@kesyas>> 1. ...can I solve it with an if trygetvalue () nested statement?

After you deserialize them, yes.

>> 2. How can I get the int value as shown in the screenshot?

You can use Convert.ToInt32 to convert the object value to int type.

>> 3. ... Playfab.PfEditor.SimpleJson are no longer used. Is that right??

It’s not recommended but you can use it if you want.

If so, is the only way to deal with json data received from Playfab is to use PlayFab.PluginManager.GetPlugin ....(testUserDataRecord.Value)?

No, it’s not the only, it’s just an encapsulation of such JSON parsing methods. You can also use other external JSON parsing methods if you want.

>> -1 Is the data that can be sent from Playfab Cloud Code to the client a JSON string or a JSON object?

It would be the Object.

>> -2 Are all result.Data values generated by API calls from clients dictionary?

The JSONObject that defined by PlayFab is the implementation of the Dictionary which owns the methods of the dictionary objects.

You can check the SDK code on your own by the “Go to definition” option in Visual Studio. More advanced questions about Unity and C# programming, you can navigate to the corresponding forum for professional supports.

More technical questions of PlayFab, we would suggest submitting new questions for them.

Comment

People who like this

0 Show 1 · 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 kesyas · May 04, 2020 at 03:56 AM 0
Share

thanks : ) i understand it

avatar image

Answer by Sarah Zhang · Apr 27, 2020 at 07:39 AM

You can uncomment a line to make SimpleJson class Internal when you need it. It would be better to use PlayFab.PluginManager.GetPlugin<ISerializerPlugin>(PluginContract.PlayFab_Serializer).DeserializeObject(testUserDataRecord.Value) to convert a string to an object which can be converted to a JsonObject. You can refer to the following code.

using System.Collections.Generic;
using UnityEngine;
using PlayFab;
using PlayFab.ClientModels;
using PlayFab.Json;
...


    public void GetUserReadOnlyData()
{
    UserDataRecord testUserDataRecord;


    PlayFabClientAPI.GetUserReadOnlyData(new PlayFab.ClientModels.GetUserDataRequest
    {
        Keys = new List<string> { "CheckInTracker" }
    }, result =>
    {


        if (result.Data.TryGetValue("CheckInTracker", out testUserDataRecord))
        {
            JsonObject testJsonObj = (JsonObject)PlayFab.PluginManager.GetPlugin<ISerializerPlugin>(PluginContract.PlayFab_Serializer).DeserializeObject(testUserDataRecord.Value);
            object testJsonValue;
            if (testJsonObj.TryGetValue("LoginStreak", out testJsonValue))
            {
                Debug.Log(testJsonValue.ToString());
            }
        }
    }, error => { });
}
...
Comment

People who like this

0 Show 0 · 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

Answer by kesyas · Apr 28, 2020 at 02:39 AM

Thank you for answer.

1. Then, if there are deeper json keys, can I solve it with an if trygetvalue () nested statement?

2. Question about the object variable obtained by out keyword.

It seems to have to be cast.

How can I get the int value as shown in the screenshot?

My code gives an error like screenshot.

3. Features like Playfab.PfEditor.SimpleJson are no longer used.

Is that right??

An error occurs when building.

If so, is the only way to deal with json data received from Playfab is to use PlayFab.PluginManager.GetPlugin <ISerializerPlugin> (PluginContract.PlayFab_Serializer) .DeserializeObject (testUserDataRecord.Value)?

4. I have a lot of questions because I don't know much about programming.

I know that JSON is used for communication between Playfab and client.

Here are two questions.

-1 Is the data that can be sent from Playfab Cloud Code to the client a JSON string or a JSON object? (I.e. whether it is a JSON object stringified through JSON.stringify or the JSON object itself)

The reason for the above question is,

in the cloudcode function,

difference between return JSON.stringify (grantedItems); and return {messageValue: message};

I want to know the difference between the above two return values.

-2 Are all result.Data values generated by API calls from clients dictionary?

The tryGetValue function is known as the Dictionary function.

Thank you!


pafaf.png (132.0 kB)
Comment
agniesportsyt

People who like this

1 Show 0 · 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

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

    4 People are following this question.

    avatar image avatar image avatar image avatar image

    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