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 Ultoman · Jun 22, 2018 at 08:57 PM · optimizationlagjsondynamicgarbage-collection

Best way to handle Deserializing a large JSON file from a website?

I am trying to get some data from a website in Unity and create objects based on that data. The data is easily retrieved using the WWW class but I am having trouble finding an easy to way create an easy to work with object to get the data I need. The JSON Utility class I have heard is not the best because I will need to create a template class for all of the data. The data is updated and is dynamic so it does not make sense to me to create a huge template class to fit a dynamic database.
JSON Object, which I found on the asset store, does exactly what I want. It allows me to create a JSON Object from a string and I am able to access data directly by index. But now I am finding out that it was coded very poorly and the garbage collection being done after I use it is so large that it causes huge lag spikes.

I thought if my lag spikes were because the asset was not coded correctly then it could be fixed with another JSON asset for Unity but I cannot find any others that work as simply as JSON Object.
Maybe there is another problem I am not seeing but right now I think the only solutions are
1. A better JSON plugin
2. A way to fix the large garbage collection spike
3. Retrieve data on a seperate thread (Which also seems to not be easy with Unity)

Ya Im stuck, any help would be appreciated.

Link to json data I am working with

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by Bunny83 · Jun 22, 2018 at 11:23 PM

Well the amount of data isn't that much. The main issue is that no matter which object representation you actually use on the C# side you will always allocate about the same amount of memory which need to be collected once you're done. Almost all JSON parsers have to completely parse all the data in order to access any of the individual values. While it would be possible to implement something like a SAX reader for JSON, i don't know any implementation and the usage would be way different than using any "normal" JSON parser.


I've written the SimpleJSON parser which tries to minimize the allocated memory. It uses stongly typed classes for the different json values and provides an easy to use interface. I've used it to store quite complex data of several MB. It also allows easy data addition or manipulation at runtime.


Within the same repository i also have some Unity specific extensions for easy read and write support of the basic Unity types (vectors, quaterion, rect, etc...)

Comment
Add comment · Show 2 · 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 elenzil · Jun 22, 2018 at 11:43 PM 0
Share

I've used Bunny83's SimpleJSON parser extensively, and it is certainly up to the task of efficiently parsing the example data from that link.

avatar image EricJ13 elenzil · Dec 26, 2018 at 11:15 PM 0
Share

Agreed, SimpleJSON is my Unity JSON parser of choice, and it's served me well on many projects.

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

97 People are following this question.

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

Related Questions

Very Bad Lag from ~20 Large Particles 0 Answers

force and delay Garbage Collection 7 Answers

Zero Garbage Policy 1 Answer

OnTriggerEnter causing lag spike? 0 Answers

Optimize (Garbage Collection, Memory usage) 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