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
0
Question by AustinK · Feb 13, 2013 at 12:55 AM · jsonjsonfx

JSONFX, Reading JSON Object

Hi,

I suppose this question is for people who have actually worked with JSonFX. I've downloaded a version of JSonFX specific to unity: here

From what I understand... you create a class the inherits from an interface (JsonConverter), which will convert the json dictionary into an object using the overridden ReadJson() function. I've created two classes that convert the passed dictionary into a C# class object. Both converter class look basically the same, but will return different types of objects, but for some reason the ReadJson function is only being called on one Converter class, and not the other.

Does anyone know of a reason why this would be happening? I have been mucking with this all day, and I can't find a reason as to why the ReadJson() func of one class is called and not the other. Both CanConvert() funcs return true and then false because it calls CanConvert on the type, then on the dictionary for some reason, but that's besides the point, which is that BOTH CanConvert() functions return true, then false, BUT afterwords ClassA's ReadJson() is called, but ClassB's ReadJson() wont be called.

I hope I haven't confused you guys too much.

Also, side question, is there a way to only grab the Dictionary of the json object?

Thank you in advance for any help.

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
0

Answer by mckamey · Feb 13, 2013 at 07:03 PM

I know a lot about JsonFx but not a lot about the changes made for the Unity fork. The JsonConverter stuff is new as JsonFx is supposed to be able to figure out the types and automatically do the type coercion itself (this is much improved in v2 rather than v1 which is what the Unity fork is from).

Just specify the type in JsonReader.Deserialize(Type) to tell it do do type coercion. To get a dictionary instead of coercing to a type, don't specify a type (this is the default).

That being said, did you tell the reader about the converter via JsonReaderSettings.AddTypeConverter(JsonConverter)? It probably knows about one via C#'s type inference, but not the other.

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 AustinK · Feb 14, 2013 at 06:35 AM 0
Share

Hey mckamey. I figured out the issue, which was that the object that was co$$anonymous$$g through was co$$anonymous$$g in as an array, even if it was just an array of 1 object. So when it would try to deserialize, the array of json objects was passed, and it would crash, but not report and error or crash the game.

You said that JsonFX will automatically do the conversion... would that be for any type, or just primitives? (Could I create my own class and pass that as a type) If so, do you think it would be better to just use the regular jsonfx from here and just drop the fork i downloaded?

Also, since I found the issue, do I post my own answer? Or just update my question.

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

10 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

Related Questions

JSON and Javascript 0 Answers

jsonfx anomalies 0 Answers

JsonFX and Polymorphism? 1 Answer

Can anyone tell me what's wrong in this, I try to post values to API 0 Answers

JsonFx Deserialize Special Characters 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