Since many byte values turn into illegal characters if you try String conversion, you will have to use base64 encoding to create a String of legal characters. The same thing happens when trying to send arbitrary bytes in a SOAP message.
Thanks William! That's exactly what I'll do. However I'm a little surprised that this is not valid. There's nothing in the JSON documentation to say that the strings can contain only printable characters. [ December 24, 2008: Message edited by: Cristian Vrabie ]
Aside from the prohibition on control characters (only some of which have replacements using \ to escape), there's the fact that a string is assumed to consist of Unicode - and you need an encoding to convert bytes to Unicode chars. Some common encodings have gaps, byte values which have no unicode value. This isn't part of the JSON spec per se, but it's part of Unicode.
Backing up a bit:
[Christian]: Do you know if there's a standard for placing a byte array in a json message.
Well, JSON itself does define a standard for arrays, and for number. A byte array is just an array of numbers, so it would look like
Using Base64 will be more compact however. Use whichever seems to meet your needs better.
Joined: Jul 09, 2008
Thanks Mike. I don't know where my head was when I was looking on that image Base64 sound good.