Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
11
Question by Azound · Nov 20, 2009 at 06:44 AM · json

What is the easiest json library to integrate with Unity?

I'm looking to integrate JSON into my game engine (rather than serializing xml). Has anybody else had any experience and can recommend a good json library? Does Unity ship with a mono-based json implementation?

Thanks!

Comment
Add comment · Show 4
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 byteprogramming · Jan 01, 2013 at 05:57 PM 0
Share

JSON can be pain in the ass if you want it to happen more than 20 times a second. All those libraries are not native and can be slow.

If you want something fast use String.split() and you can create any structure you want.

avatar image mckamey · Feb 13, 2013 at 05:51 PM 3
Share

This isn't very good advice.

First of all, most decent JSON parsers can do thousands or tens of thousands per second, so 20 per second is not a very high bar.

Secondly, String.split() is going to produce structures which are very difficult to navigate especially when you get into nested JSON objects.

Finally, the memory used by successive String.split() (to produce arrays of strings) will slow your execution down considerably more than a proper lexer/parser.

avatar image Bovine · Feb 19, 2013 at 01:45 PM 0
Share

Agree with @mckamey String.Split() is terrible advice for the reasons he says.

avatar image Bovine · Feb 22, 2013 at 10:59 AM 0
Share

@Fattie I had some problems with that library:

  1. cannot decode an exponential float when it has encoded it itself

  2. does not auto escape strings

  3. dos not support dictionary types

  4. does not tolerate missing variables

I tried fastJson but it was too clever and was injecting IL so blew up immediately and probably wouldn't work on iOS and LitJson may be no better - does not have a method to escape a string??? Does not auto escape on its own.

I may need to either work around the libraries short-cum$$anonymous$$gs or write my own (ugh).

11 Replies

· Add your reply
  • Sort: 
avatar image
3
Best Answer

Answer by Ashkan_gc · Nov 20, 2009 at 07:40 PM

you can use this JSON library. JSONsharp

also you can go to JSON's official web site

to get more info

Comment
Add comment · Show 8 · 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 Bovine · Feb 22, 2013 at 11:01 AM 0
Share

Last update in 2007... eek

avatar image Fattie · Apr 17, 2013 at 08:43 AM 1
Share

Unfortunately 'jsonsharp' pack seems largely useless. I use and have previously strongly recommended:

"X$$anonymous$$L-JSON Serialization" from the Asset store ..

http://www.aworldforus.com/xml-json-serialization/

It is extremely easy to use,documented, continuously developed and they answer email instantly. Eg:

 var stream:JSONOutStream = new JSONOutStream( );
 stream
   .Content("name", "$$anonymous$$")
   .Content("height", 1.12)
   .End();
 Debug.Log("JSON done... " + stream.Serialize() );

HOWEVER, PLEASE NOTE BOVINE'S CO$$anonymous$$$$anonymous$$ENTS ON THIS PAC$$anonymous$$AGE, BELOW.

avatar image Bovine · Apr 17, 2013 at 08:48 AM 0
Share

As stated above I had the following issues with this X$$anonymous$$L-JSON lib on the asset store:

  1. cannot decode an exponential float when it has encoded it itself

  2. does not auto escape strings

  3. does not support dictionary types

  4. does not tolerate missing variables - i.e. if I have extended a class previously serialized

Using it as @Fattie is might be better that automatic serialization... Also, some of the above may have been fixed now.

Looking at the code I also felt it looked a tad hacky. It's cheapish and functional however, but for me the above points killed it, though I could handle point 3 missing had 1 and 2 been present and point 4 might have been something I could stomach, but if you use it to save game data for instance and then add to that structure it just won't deserialize that structure anymore and your save is toast.

avatar image Bunny83 · Apr 17, 2013 at 10:07 AM 1
Share

You could also use my SimpleJSON parser ;) It's actually the most advanced one around, but still doesn't have an own type for the different "JSON value types". However there are easy to use casting properties like ToInt, ToFloat, ... which can be used to read to write a value.

There's an implicit string to JSONData and JSONData to string operator, so it's very easy to use. I use it myself all across my project to save the levels the user can build, compress them, load from or send to a server, ... The targetplatform of my game is Android and iOS but it works on most others as well except Webplayer and flash for the time being due to file access routines.

I will update it when i have some time, but at the moment there isn't any ;)

ps: It does read it's own format and does escape critical stuff (namely '\\', '\"', '\n', '\r', '\t', '\b', '\f')

avatar image Fattie · Apr 17, 2013 at 10:20 AM 1
Share

@bov for future readers, per your question title I believe the EASIEST one to use is the "aworldifus" one mentioned. I am a leading expert on finding the "easiest" thing to use, believe me :-) (ie, my general stupidity and incompetence is proof os ease of use .. "if Fattie can install and use it ANYONE can use it" :) )

Show more comments
avatar image
4

Answer by PaulT · Nov 20, 2009 at 09:19 PM

I use LitJSON in my projects. This is also soon to be implemented officially in u3dobject, for embedding unity and communicating between Unity and Flash on a website.

Personally I find this the easiest library to use.

Comment
Add comment · Show 6 · 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 Ricardo · Dec 13, 2009 at 04:12 PM 0
Share

Hi Paul. I tried to use LitJSON, but run into a "max allowed depth" exception for pretty much anything I try to serialize - even if I'm simply trying to serialize a float. Did you encounter this?

avatar image CJCurrie · Jul 10, 2010 at 08:21 PM 0
Share

I've found that whenever I want to serialize a float I usually need to truncate it to a few decimal places to avoid getting the "max allowed depth" errors. A single float is a lot of numbers, though, so to conserve bandwidth you'd probably better be doing that anyway.

avatar image mindlube · Jan 01, 2011 at 09:13 PM 0
Share

I have the same problem with LitJSON. It fails in Ints as well :( JsonException: $$anonymous$$ax allowed object depth reached while trying to export from type System.Int32 LitJson.Json$$anonymous$$apper.WriteValue (System.Object obj, LitJson.JsonWriter writer, Boolean writer_is_private, Int32 depth) (at Assets/Plugins/LitJson/Json$$anonymous$$apper.cs:761) LitJson.Json$$anonymous$$apper.WriteValue (System.Object obj, LitJson.JsonWriter writer, Boolean writer_is_private, Int32 depth) (at Assets/Plugins/LitJson/Json$$anonymous$$apper.cs:753)

avatar image yoyo · May 27, 2013 at 06:58 PM 0
Share

LitJSON doesn't support type-hinting, so you need to know at compile time which type you are deserializing. If you need to be able to deter$$anonymous$$e the type dynamically (for example to deserialize derived classes) then you'll need to add support for type hinting, or use another library, such as Json.NET.

avatar image hiddenspring81 · May 27, 2013 at 07:15 PM 0
Share

From my experience LitJSON really does not work well on AOT compiled platforms, such as iOS and the Xbox360.

Show more comments
avatar image
4

Answer by Tetrad · Feb 18, 2011 at 05:35 PM

http://forum.unity3d.com/threads/35484-MiniJSON-script-for-parsing-JSON-data?p=231056

Comment
Add comment · Show 1 · 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 hiddenspring81 · May 27, 2013 at 07:18 PM 0
Share

I'm a fan of $$anonymous$$iniJSON. It's extremely simple to use, and is the most portable, reliable, Unity3D compatible JSON parsing library that I've used. I've used it on when targetting Web, iOS, Android, and desktop PC standalone, without any problems, which is more than I can say about other JSON libraries (ie: LitJson).

avatar image
2

Answer by Brian-Kehrer · Nov 21, 2009 at 03:27 AM

We have a customized JSON library jormungandr rebuilt based on Jayrock. It is far smaller than the default Jayrock library (which uses XML for some reason - we removed that), and we have recompiled it for .net 1.1 so it can be used on the iPhone as well. The final size is very very small, not even close to System.XML

Comment
Add comment · Show 4 · 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 mindlube · Jan 01, 2011 at 09:21 PM 0
Share

$$anonymous$$, excellent I sent you a P$$anonymous$$. thx

avatar image by0log1c · Mar 17, 2011 at 01:30 PM 0
Share

Any possibility to post a link? I'd be interested to take a look. I'm looking for the lightest /app/ possible :)

avatar image EisenbergEffect · Nov 20, 2012 at 02:28 AM 0
Share

Link please? :)

avatar image ina · Apr 16, 2013 at 11:20 PM 0
Share

link? or is it now borked with recent unity fragmentation..

avatar image
0

Answer by Macarse · Jan 19, 2012 at 03:03 PM

MiniJSON is also an option. Check the src code here.

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
  • 1
  • 2
  • 3
  • ›

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

17 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

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Can someone help me fix my Javascript for Flickering Light? 6 Answers

Setting Scroll View Width GUILayout 1 Answer

Material doesn't have a color property '_Color' 4 Answers

"Object reference not set to an instance of an object" when attempting to parse Dictionary of Lists with JSONFx, MiniJSON 0 Answers


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