Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Replacing Dynamic keyword

Discussion in 'Editor & General Support' started by Risine, Apr 10, 2022.

  1. Risine

    Risine

    Joined:
    Dec 10, 2009
    Posts:
    154
    Hello,
    how can I replace the dynamic keyword here to avoid using Net 4.x :
    Code (CSharp):
    1.  
    2.         string json = ".......";
    3.         string data = ".......";
    4.         dynamic obj = JsonConvert.DeserializeObject(json);
    5.         return JsonConvert.DeserializeObject<T>(JsonConvert.SerializeObject(obj[data]));
    6.  
    Thanks!
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,756
    I don't think there is a generic "replace" mechanism, but you should be able to do what you need by following standard JSON data processing steps as used in Unity.

    Also, keep in mind potential problems with Unity "tiny lite" built-in JSON:

    In general I highly suggest staying away from Unity's JSON "tiny lite" package. It's really not very capable at all and will silently fail on very common data structures, such as Dictionaries and Hashes and ALL properties.

    Instead grab Newtonsoft JSON .NET off the asset store for free, or else install it from the Unity Package Manager (Window -> Package Manager).

    https://assetstore.unity.com/packages/tools/input-management/json-net-for-unity-11347

    Also, always be sure to leverage sites like:

    https://jsonlint.com
    https://json2csharp.com
    https://csharp2json.io
     
  3. Risine

    Risine

    Joined:
    Dec 10, 2009
    Posts:
    154
    Hi, Im' using Newtonsoft JSON .NET already, and just want to get rid off the dynamic keyword to be able to build on WebGL.