Unity & JSON

Background

Working with JSON messages is a crucial aspect of the GCS design. This is because the protocol for communications between Unity and ROS entails serializing and deserializing JSON messages in order to bridge the gap between the software created by the "language barrier" between Unity and ROS. Put simply, we need to use JSON messages in order to handle (most of) our integration between ROS and Unity.

Listed below are some useful tools for working with JSON messages. Please note that SimpleJson, which comes with ROSBridgeLib, has proven to be the go to tool for our implementation.

Unity & JSON

Unity has built in features to handle JSON Serialization.

A guide is provided for accomplishing this task for basic objects:

https://docs.unity3d.com/Manual/JSONSerialization.html

NewtonsoftJSON

However, the default tools provided by Unity are not enough to handle serialization of more complex objects such as arrays and other complex classes and/or data structures. To achieve this task it is helpful to download JSON.NET which is a popular high-performance JSON framework for .NET.

This can be downloaded here: https://www.newtonsoft.com/json.

Note that Installation is a bit tricky due to a version conflict between Unity and JSON.NET.

*Unity only supports version 3.5 and its predecessors.

In order to circumvent this software conflict we recomend downloading the ZIP file contaning JSON.NET directly from the site rather than dowloading through nuget (since nuget will install the newest version, version 4.5).

Once the zip file is downloaded unzip it and navigate to the folder. From there navigate to the BIN folder contained within. From here navigate to the net35 folder and find the dll file contained within. Click and drag this into your Unity project and you will now have a very helpful tool for working with JSON in your unity project.

Here is the documentation for JSON.NET: https://www.newtonsoft.com/json/help/html/Introduction.htm

Here is a helpful video that goes over setting up JSON.NET in unity: https://www.youtube.com/watch?v=69jswCNtATM&lc=z234x3shcwvig1qloacdp4331mnjezsguchax3sstytw03c010c.1505583491747068

SimpleJSON

Also note, that simpleJSON is another handy tool for working with JSON messages. It is provided with ROSBridgeLib (along with websocketsharp). Note that ROSBridgeLib is an asset that will almost certainly be used if you are working with our GCS design. However, if this is for some reason not the case, please note that simpleJSON has proven to be a handy tool for our implementation. (In fact, it ended up being used more heavily than NewtonsoftJSON.)

results matching ""

    No results matching ""