Hello, I am trying to receive Json object over UDP where Json object is sent as bytes. I already tested that Unity successfully receives the message sent.
My Json object looks like this:
{
"obj1": {
"Type": "Enemy",
"posX": "10",
"posY": "1",
"posZ": "20",
"rotX": "0",
"rotY": "0",
"rotZ": "0"
},
"obj2": {
"Type": "Civilian",
"posX": "23",
"posY": "0.75",
"posZ": "15",
"rotX": "0",
"rotY": "0",
"rotZ": "0"
}
}
What I want to do is
- Parse this and
- Instantiate these objects.
How can I save this? I have the following serializable class:
[System.Serializable]
public class NewSpecInfo{
public string objectType;
public float posX;
public float posY;
public float posZ;
public float rotX;
public float rotY;
public float rotZ;
// Add more variables that goes into spec in newScenario(spec)
public static NewSpecInfo CreateFromJSON(string jsonString){
return JsonUtility.FromJson<NewSpecInfo>(jsonString);
}
}
I checked How to read .json file but mine is in different format and I have hard time dealing with (it is my first time dealing with json and also new to Unity…). Thanks in advance, and sorry if my question is not clear…