Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    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,513
  3. tonemcbride

    tonemcbride

    Joined:
    Sep 7, 2010
    Posts:
    1,083
    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:
    7,186
    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.