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
1
Question by R-GiGgS84 · Oct 17, 2011 at 10:37 AM · jsonunify

Improper JSON formatting when decode JSON in Unity3D

Hi people,

I am using the JSON parser from the Unify Community Wiki as below:

http://www.unifycommunity.com/wiki/index.php?title=JSONObject

I follow the instruction in setting up the JSON parser and this is how i call the JSON parser as below:

http://pastebin.com/tCnQipUZ

However, i keep getting the error as below:

improper JSON formatting:file://D:/Project Files/Unity Project (Jukebox_r10)/Assets/Resources/sample.json UnityEngine.Debug:LogWarning(Object) JSONObject:.ctor(String) (at Assets/Customized Script/JSONObject.cs:126) Startup:Update() (at Assets/Customized Script/Startup.cs:20)

Can any kind soul enlight me on what is really going wrong in my script?

Thanks in advance. :)

Comment
Add comment · Show 7
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 R-GiGgS84 · Oct 23, 2011 at 07:01 AM 0
Share

Anyone can help on this?

avatar image syclamoth · Oct 23, 2011 at 07:08 AM 0
Share

This is kind of a specialist problem! I use a certain amount of serialization in my work, but that's all either straight binary, or X$$anonymous$$L- I'm not really sure I can help you here!

avatar image R-GiGgS84 · Oct 23, 2011 at 09:06 AM 0
Share

Thank you for your reply. Are you indicating in order to extract JSON, i will need to come out with my own JSON parser?

avatar image syclamoth · Oct 23, 2011 at 09:39 AM 0
Share

As I said, I really don't know- I have virtually no knowledge of this specific system. You might have one already, I don't know.

avatar image Jace · Oct 23, 2011 at 12:41 PM 2
Share

just a guess, but is it really getting the file sample.json from your file system or trying to parse the string pertaining to the location? I assume you've checked the file itself and it parses ok outside unity. Try hard-coding the json string within your script and decoding that just to check it works.

Show more comments

1 Reply

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

Answer by gfr · Oct 23, 2011 at 01:56 PM

As Jace guesses in the comments, JSONObject doesn't take an encoded string but a filename. With what you have it tries to decode the filename as JSON, which of course fails.

So you have to load the JSON string yourself:

 string encodedString = LoadStringFromFile(); // your function...
 JSONObject j = new JSONObject(encodedString);
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 R-GiGgS84 · Oct 23, 2011 at 04:06 PM 0
Share

Hi Jace & gfr,

Thank you for the reply. Can you give me an idea how the LoadStringFromFile() work?

avatar image gfr · Oct 23, 2011 at 04:42 PM 0
Share

That's for you to implement, e.g.:

 StreamReader sr = new StreamReader(path);
 string encodedString = sr.ReadToEnd();
 sr.Close();
avatar image R-GiGgS84 · Oct 24, 2011 at 01:20 AM 0
Share

Hi gfr,

Will give it a try let you guys know if everything went through.

Thanks again for the assistance again. :)

avatar image R-GiGgS84 · Oct 25, 2011 at 09:24 AM 0
Share

I realized that the JSONObject only work on certain JSON if you got the format that is been desired by the JSONObject Class. So ins$$anonymous$$d, i used the LitJSON and everything work pretty fine.

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

C# JSON library 6 Answers

IOS Parse Json 0 Answers

Is there a reason not to use system.json.dll? 2 Answers

SimpleJSON array problem 0 Answers

How to import Long and Lat (GPS Info) from a flat file and render the points. 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