- Home /
Parseing JTokens
Im using Airconsole to make custom phone controllers, and am having issues with interpreting the messages sent from the controllers.
Below is the c# code i am using to recieve messages:
//intercepting void OnMessage(int from, JToken data) { Debug.Log("input from " + from + ": " + data.ToString()); if (data.Value ("jump")) { Debug.Log("Jump"); } }
This is from the debug log:
//sent from controller input from 3: { "grab": { "pressed": true, "message": {} } }
This is the error i get when pressing the Jump button, no other button throws errors.
InvalidCastException: Cannot cast Newtonsoft.Json.Linq.JObject to Newtonsoft.Json.Linq.JToken. Newtonsoft.Json.Linq.Extensions.Convert[JToken,Boolean] (Newtonsoft.Json.Linq.JToken token) (at Assets/AirConsole/plugins/Newtonsoft.Json/Linq/Extensions.cs:261) Newtonsoft.Json.Linq.JToken.Value[Boolean] (System.Object key) (at Assets/AirConsole/plugins/Newtonsoft.Json/Linq/JToken.cs:243) debugger.OnMessage (Int32 from, Newtonsoft.Json.Linq.JToken data) (at Assets/debugger.cs:24) NDream.AirConsole.AirConsole+c_AnonStorey4.<>m_0 () (at Assets/AirConsole/scripts/AirConsole.cs:1153) NDream.AirConsole.AirConsole.Update () (at Assets/AirConsole/scripts/AirConsole.cs:1020)
Your answer
![](https://koobas.hobune.stream/wayback/20220612131102im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
I don't understand how save to QualitySettings.SetQuality with a json file 1 Answer
EasyJSON Casting Error 3 Answers
Getting data out of Dictionary 0 Answers
JSON into Unity Class 4 Answers