Search Unity

JSON Parse Issue

Discussion in 'Scripting' started by seanbiganski, Dec 9, 2019.

  1. seanbiganski

    seanbiganski

    Joined:
    Aug 17, 2016
    Posts:
    15
    Can someone tell me what the class should look like to parse to JSON like this:

    {
    "All": {
    "All": [
    "All",
    "Lincoln Memorial University",
    "Louisiana State University",
    "Mississippi State University"
    ],
    "Suture Pattern": [
    "All",
    "Louisiana State University",
    "Mississippi State University"
    ],
    "Urinary": [
    "All",
    "Lincoln Memorial University",
    "Louisiana State University"
    ],
    "Incision Tech": [
    "All",
    "Louisiana State University",
    "Mississippi State University"
    ],
    "Surgical Prep": [
    "All",
    "Lincoln Memorial University",
    "Louisiana State University",
    "Mississippi State University"
    ],
    "Abdominal": [
    "Louisiana State University"
    ],
    "Dermatology": [
    "Louisiana State University"
    ],
    "Clinical Pathology": [
    "Lincoln Memorial University"
    ],
    "Anesthesia": [
    "Lincoln Memorial University"
    ],
    "Reproductive": [
    "All",
    "Lincoln Memorial University",
    "Louisiana State University",
    "Mississippi State University"
    ],
    "Upper Respiratory": [
    "Louisiana State University"
    ],
    "Gastrointestinal": [
    "Louisiana State University"
    ],
    "Closure Tech": [
    "Mississippi State University"
    ],
    "Orthopedic": [
    "Louisiana State University"
    ],
    "Anatomy": [
    "Louisiana State University"
    ],
    "Theriogenology": [
    "Lincoln Memorial University"
    ]
    },
    "Skill": {
    "All": [
    "All",
    "Lincoln Memorial University",
    "Louisiana State University",
    "Mississippi State University"
    ],
    "Anesthesia": [
    "Lincoln Memorial University"
    ],
    "Clinical Pathology": [
    "Lincoln Memorial University"
    ],
    "Closure Tech": [
    "Mississippi State University"
    ],
    "Incision Tech": [
    "All",
    "Louisiana State University",
    "Mississippi State University"
    ],
    "Surgical Prep": [
    "All",
    "Lincoln Memorial University",
    "Louisiana State University",
    "Mississippi State University"
    ],
    "Suture Pattern": [
    "All",
    "Louisiana State University",
    "Mississippi State University"
    ],
    "Theriogenology": [
    "Lincoln Memorial University"
    ],
    "Urinary": [
    "Lincoln Memorial University"
    ]
    },
    "Canine": {
    "Abdominal": [
    "Louisiana State University"
    ],
    "All": [
    "All",
    "Lincoln Memorial University",
    "Louisiana State University",
    "Mississippi State University"
    ],
    "Anatomy": [
    "Louisiana State University"
    ],
    "Dermatology": [
    "Louisiana State University"
    ],
    "Gastrointestinal": [
    "Louisiana State University"
    ],
    "Incision Tech": [
    "Louisiana State University"
    ],
    "Reproductive": [
    "All",
    "Lincoln Memorial University",
    "Louisiana State University",
    "Mississippi State University"
    ],
    "Theriogenology": [
    "Lincoln Memorial University"
    ],
    "Urinary": [
    "Louisiana State University"
    ]
    },
    "Equine": {
    "All": [
    "All",
    "Lincoln Memorial University",
    "Louisiana State University"
    ],
    "Anesthesia": [
    "Lincoln Memorial University"
    ],
    "Orthopedic": [
    "Louisiana State University"
    ],
    "Upper Respiratory": [
    "Louisiana State University"
    ]
    },
    "Feline": {
    "Reproductive": [
    "All",
    "Lincoln Memorial University",
    "Louisiana State University",
    "Mississippi State University"
    ]
    }
    }

    Thank you
     
  2. Olmi

    Olmi

    Joined:
    Nov 29, 2012
    Posts:
    625
    Hi,
    Did you even do a superficial search about this, like Unity JSON parser? And please use code blocks for code. And it wouldn't probably have needed much more effort to run some beautify/format in some editor.

    There are many discussions here on Unity forums how to parse JSON data using Unity's own tools, search for them first to get an overall idea. But It's probably best idea to look for some 3rd party JSON library as Unity's JsonUtility isn't very flexible.
     
  3. seanbiganski

    seanbiganski

    Joined:
    Aug 17, 2016
    Posts:
    15
    Yes, I have done several searches and am parsing other JSON. It is this specific format I am having trouble with. But I will look for 3rd party libraries. I am using Unity's.
     
  4. seanbiganski

    seanbiganski

    Joined:
    Aug 17, 2016
    Posts:
    15
  5. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    4,877
    I usually use http://json2csharp.com/ if I have any questions on class structure. But I also generally use json.net instead of Unity's json.
     
    Kurt-Dekker likes this.
  6. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    4,843
    For the above data that OP posted, it looks like a Dictionary, which means you MUST use something besides Unity's JSON. Unity's JSON is more like a "tiny JSON" intended for performant deserialization of pre-structured data only, not free-form JSON.

    There is a JSON.NET available on the asset store for free, works awesome.
     
unityunity