unity – Parse JSON without providing a class to deserialize to


I’m trying to parse a very large JSON string in Unity. I do not need all the fields and I can’t create a class with all the members. It appears that all examples I have found, including the official docs, always deserialize and map to class members, which I cannot do for my application.

I tried creating a class that is similar to the JSON string, meaning that it has some members of the target JSON, but to no avail. All members are always undefined.

Here’s part of the string:

{
    "Robots":({"CanReset":false,
    "CycleTime":123.875,
    "Info":null,
    "LevelInfo":null,
    "Name":"FTF_10033",
    "State":0,"
    ...
    }, ...
}

So I tried creating these classes:

(Serializable)
public class jsonData
{
    public Robot() robots;
}

(Serializable)
public class Robot
{
    public string Name = "Unknown AGV";
}

And printing the results:

var jsonString = www.downloadHandler.text;
jsonData jsonData_ = JsonUtility.FromJson<jsonData>(jsonString);
Debug.Log("Json data: " + jsonData_);
Debug.Log("Robots: " + jsonData_.robots);

jsonData_ prints Json data: jsonData_, and jsonData_.robots prints nothing (just Robots:).

Is there any way to parse JSON without a class?

I would be content with something like jsonString(“robots”)(0)(“name”) or something.

Thank you!