JsonUtility spitting out weird values for unsigned long integers

I’m having some issues with JsonUtility.FromJson. For some reason, whenever I try to parse an unsigned long int with a value of ‘0’, it spits out some value around 89 million.

This is what I’m putting into JsonUtility:


And this is what I get out:


All of the values which are showing up as 88.95 million are supposed to be zero. But, unlike the other zeros in the raw text, these zeros are being stuck into ulongs. So I’m assuming that JsonUtility just hates ulongs, which isn’t awesome, but what can I do to work around this? Or am I making some error?

Unless you exceed the 9,223,372,036,854,775,807 limit of singed long, you should prevent using unsigned types where ever it is possible, even if you are only dealing with positive numbers. Otherwise you might introduce weird issues as you encountered here.

Also CLS (Common Language Specification) is a thing you should keep in mind, especially if you want to compile to other platforms, that don’t support unsigned types.

See MSDN Language Independence and Language-Independent Components for further information on that topic.

You’re right, Bunny83, those strings shouldn’t be strings. I must have been using PHP’s json_encode method wrongly, forcing it to stringify all my integers – then turning around and asking JsonUtility to unstrigify them. No wonder it got confused