• Categories
  • Recent
  • Tags
  • Popular
  • Solved
  • Unsolved
  • Users
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (Darkly)
  • No Skin
Collapse
brainCloud Forums
H

Henry Smith

@Henry Smith
About
Posts
1
Topics
1
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

    Recommended way to read Entity data? (Unity, C#)
  • H Henry Smith

    Hi, I'm experimenting with brainCloud in Unity (C#) and I'm trying to read a Global Entity. I can get the JSON of the Entity object but then what's the best way to access the "data" key inside? I can do it in a convoluted way but I'm hoping there's a friendlier way using the API.
    Here's some sample code with questions in the comments:

    string entityId = "whatever";
    SuccessCallback successCallback = (jsonResponse, cbObject) =>
    {
    	// Unity's JsonUtility doesn't support Dictionaries so I guess I should use brainCloud's internal JsonReader?
    	// And is there a more specific class I can Deserialize to, or should I just use generic Dictionaries?
    	var responseDict = JsonReader.Deserialize<Dictionary<string, object>>(jsonResponse);
    	var entityDict = responseDict["data"] as Dictionary<string, object>;
    	var myDataDict = entityDict["data"] as Dictionary<string, object>;
    
    	// Now I have my data as a Dictionary, but ideally I want to deserialize it into my own custom class type...
    	// So should I *re-serialize* it back to JSON so I can read it? This seems unnecessary.
    	var myDataJson = JsonWriter.Serialize(myDataDict);
    	var myData = JsonReader.Deserialize<MyCustomClass>(myDataJson);
    
    	// Now I have my data in the correct form!
    };
    FailureCallback failureCallback = (status, reasonCode, jsonError, cbObject) => {};
    
    _bc.GlobalEntityService.ReadEntity(entityId, successCallback, failureCallback);
    

    Seems like there's probably an easier way to do it, just wondering what you recommend?
    Thanks!

  • Login

  • Login or register to search.
  • First post
    Last post
0
  • Categories
  • Recent
  • Tags
  • Popular
  • Solved
  • Unsolved
  • Users