Search Unity

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

  2. Unity 2022.1 is now available as the latest Tech release.
    Dismiss Notice
  3. Improve your project's performance with our new guide on profiling in Unity.
    Dismiss Notice

[Solved] About JsonUtility

Discussion in 'Scripting' started by jbvobling, Mar 8, 2018.

  1. jbvobling

    jbvobling

    Joined:
    Sep 26, 2017
    Posts:
    27
    I have a Json file like this:
    Code (csharp):
    1.  
    2. {
    3.     data:
    4.     [
    5.         {
    6.             features:
    7.             {
    8.                 name:"oi"
    9.             }
    10.         },
    11.         {
    12.             features:
    13.             {
    14.                 age:"15"
    15.             }
    16.         },
    17.         {
    18.             features:
    19.             {
    20.                 job:"game"
    21.             }
    22.         }
    23.     ]
    24. }
    25.  
    My question would be, is there a way to use JsonUtility.FromJson<CustomClassDataFormat>(stringJson) without creating any CustomClassDataFormat?

    What I want to know if its possible to get the key and value of the jsonFile without creating any "JSON Serialization" file.
     
    Last edited: Mar 9, 2018
  2. lordofduct

    lordofduct

    Joined:
    Oct 3, 2011
    Posts:
    8,023
  3. tonemcbride

    tonemcbride

    Joined:
    Sep 7, 2010
    Posts:
    1,043
    Your JSON doesn't appear to be valid either - you can use https://jsonlint.com/ to validate it, it's handy to check.
     
  4. jbvobling

    jbvobling

    Joined:
    Sep 26, 2017
    Posts:
    27
    My JSON is valid in unity because I tested and I did get the data. I think in that link, some of the algorithm is not supported.
     
  5. jbvobling

    jbvobling

    Joined:
    Sep 26, 2017
    Posts:
    27
  6. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    6,564
    Depending on what json serializer you use, it's not valid json. JsonUtility is super fast, but it tends to be a bit more limited in what it can do. I tend to prefer json.net as it handles a lot of things fairly well from what I have seen vs the others.
     
unityunity