JSON issues

Is bool supported in JSON serializer?

i get this error:

#### Exception System.Exception - 0x00000000 (3) ####
#### Message: unsupported type for Marshall
#### GHIElectronics.TinyCLR.Data.Json.SerializationUtilities::Marshall [IP: 0410] ####
#### GHIElectronics.TinyCLR.Data.Json.JValue::ToBson [IP: 0012] ####
#### GHIElectronics.TinyCLR.Data.Json.JProperty::ToBson [IP: 000f] ####
#### GHIElectronics.TinyCLR.Data.Json.JToken::ToBson [IP: 001e] ####
#### GHIElectronics.TinyCLR.Data.Json.JObject::ToBson [IP: 0031] ####
#### GHIElectronics.TinyCLR.Data.Json.JToken::ToBson [IP: 001e] ####
#### GHIElectronics.TinyCLR.Data.Json.JToken::ToBson [IP: 0019] ####
#### VepelDevice.Connect::Write [IP: 000a] ####
#### VepelDevice.Program::Connect_DataReceived [IP: 0071] ####
#### VepelDevice.Connect::UsbClient_DataReceived [IP: 000a] ####
#### GHIElectronics.TinyCLR.Devices.UsbClient.UsbClientController::OnDataReceived [IP: 000e] ####
#### GHIElectronics.TinyCLR.Devices.UsbClient.Provider.UsbClientControllerApiWrapper::<.ctor>b__8_0 [IP: 001c] ####
 Uncaught exception 

Also i tried JSON from WebApi app and it can deserialize correctly, now im trying out Winforms app over serial port with newtonsoft json and its not working.
What are my options for serialization from winforms to tinyclr?

Why is .ToString prettifying JSON?
Is .ToBson also doing this?
Im gonna try to convert that string to byte array and send it that way over serial port.

I do not think it is but we can investigate. This library is provided by the expert @mcalsyn so maybe he can provide some direction.

I’ll take a look.

I flagged this for deletion, it works now for me…

Ok - good to hear - I have been working today on a fix for issue 540 that I will be PR’ing shortly which will also robustify type handling.

1 Like

Can you share what you did wrong to help others?

Didnt use .ToBson. Did it this way:

            JToken json = JsonConverter.Serialize(data);
            string jsonString = json.ToString();
            byte[] jsonBytes = Encoding.UTF8.GetBytes(jsonString);
            return jsonBytes;