In the example we receive data from a Nintendo Wii remote control in JSON Format like in the attached *.txt file.
To deserialize this JSON data which is coming e.g. via UDP, we need a class structure in our script.
To deserialize this JSON data which is coming e.g. via UDP, we need a class structure in our script.
This structure can be easily created with a JSON to C# converter like
The JSON structure from the *.txt file is copied into the converter and then the convert button is pressed
and then the resulting class structure can be copied into the script.
In the attached example project file there is a script with this structure.
It deserializes the string using the created class structure and creates three example out ports at the script block with data from the JSON string:
public static void Run(string jsonString, out int AccelCalibrationInfoX0, out double ButtonStateDown, out int AccelStateRawValuesY)
{
Root root = JsonConvert.DeserializeObject<Root>(jsonString);
AccelCalibrationInfoX0 = root.AccelCalibrationInfo.X0;
ButtonStateDown = root.Battery;
AccelStateRawValuesY = root.AccelState.RawValues.Y;
}
To test this with the attached show you can send the example Json data e.g. via Packet Sender to Sympholight and then execute the script block.