Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only. On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live. Read our full announcement for more information and let us know if you have any questions.

Feature Request get a deserialized object from getJson

Discussion in 'Unity Remote Config' started by Meresman, Aug 23, 2022.

  1. Meresman

    Meresman

    Joined:
    Sep 15, 2019
    Posts:
    9
    Hi, I'm trying to use Remote config services and wondered, why does getJson returns a string and not a deserialized object?
    I noticed JsonConvert is already used to serialize in that class. why not create a - public T GetJson<T>(...)?

    code from RuntimeConfig.cs:
    Code (CSharp):
    1.  
    2.         /// <summary>
    3.         /// Retrieves the string representation of the JSON value of a corresponding key from the remote service, if one exists.
    4.         /// </summary>
    5.         /// <param name="key">The key identifying the corresponding setting.</param>
    6.         /// <param name="defaultValue">The default value to use if the specified key cannot be found or is unavailable.</param>
    7.         /// <returns>A string representation of the JSON value of a corresponding key from the remote service, if one exists. If one does not exist, the defaultValue is returned ("{}" if none is supplied.)</returns>
    8.         public string GetJson(string key, string defaultValue = "{}")
    9.         {
    10.             try
    11.             {
    12.                 return _config[key].ToString();
    13.             }
    14.             catch
    15.             {
    16.                 return defaultValue;
    17.             }
    18.         }
     

    Attached Files: