Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by truehatch · Mar 30, 2017 at 04:03 PM · serializationjson

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:

 {"charId":"2","entityName":"wod","entityLevel":"1","path":"0","sex":"female","exp":"0","zenny":"0","maxVita":"1","maxMana":"1","might":"1","will":"1","grace":"1","grit":"1","zeal":"1","sleight":"1","statPoints":"0","karma":"0","nation":"0"}

And this is what I get out:

alt text

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?

capture5.png (3.4 kB)
Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image truehatch · Mar 30, 2017 at 02:52 PM 0
Share

After switching to Newtonsoft.Json.Net, everything worked fine. So I guess this is just a bug with Unity's JsonUtility.

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by beStrange · Mar 30, 2017 at 04:15 PM

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.

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Adam-Mechtley · Mar 30, 2017 at 06:39 PM 0
Share

That said, please do still file a bug report on this, as it should be handled better

avatar image Bunny83 Adam-Mechtley · Mar 31, 2017 at 08:25 AM 0
Share

But first he might want to try using actual "numbers" inside his JSON representation. Currently all values are stored as "strings".

I mean it should look like this:

 {
     "charId": 2,
     "entityName": "wod",
     "entityLevel": 1,
     "path": 0,
     "sex": "female",
     "exp": 0,
     "zenny": 0,
     "maxVita": 1,
     "max$$anonymous$$ana": 1,
     "might": 1,
     "will": 1,
     "grace": 1,
     "grit": 1,
     "zeal": 1,
     "sleight": 1,
     "statPoints": 0,
     "karma": 0,
     "nation": 0
 }

Since the three values we can see in the screenshot are all slightly different, it seems unlikely that they are returned by the JSONUtility.

Finally keep in $$anonymous$$d that the JSON format stores / expects numbers as double precision floating point values. So whenever your value gets "too large" it will be represented in scientific notation. Of course you could store a number as string, but in this case you can't rely on the automatic conversion as again, JSON uses double for numbers. You would need to read the value as actual string and parse it yourself as ulong.

avatar image Adam-Mechtley Bunny83 · Mar 31, 2017 at 08:49 AM 0
Share

Good catch!

avatar image
0

Answer by truehatch · Apr 02, 2017 at 10:01 AM

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

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Best Way to Store Large Number of GameObjects? 1 Answer

unity 3d loading data from json problem?! 1 Answer

MiniJSON Multiple Rows 1 Answer

JsonUtility not found / working 0 Answers

JsonUtility.fromJson won't work with german Umlauts ä ü ö 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges