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 /
  • Help Room /
This question was closed May 25, 2017 at 02:09 AM by jwvanderbeck for the following reason:

Other

avatar image
1
Question by jwvanderbeck · May 25, 2017 at 01:29 AM · json

Unity imposed recursion depth of Json data?

Is Unity imposing some maximum depth level on JSON objects? I will include the full code at the bottom, but essentially I have something like this:

I have a property List CustomClassA where CustomClassA also has a property that is a List CustomClassB. Both CustomClassA and CustomClassB are properly marked up for serialization.

Now if I use JsonUtility.ToJson on an individual element in List CustomClassA , in other words on a single CustomClassA, then the JSON output is as expected. It properly contains all the elements of the List CustomClassB that is contained by the CustomClassA object. So I know that the JSON serialization of a custom object in a List works.

However if I try to use JsonUtility.ToJson on the entire List CustomClassA I just get back an empty JSON object "{}" rather than a nested array of objects as expected.

 using System.Collections;
 using System.Collections.Generic;
 using System;
 using UnityEngine;
 
 [Serializable]
 public class ComponentProperty
 {
     // Name of the property
     public string Key;
     // Units to display after the value, such as kg, m/s, m, etc.
     public string Units;
     [SerializeField]
     private string value;
 
     public string GetStringValue()
     {
         return value;
     }
 
     public float GetFloatValue()
     {
         float outValue = float.NaN;
         float.TryParse(value, out outValue);
         return outValue;
     }
 
     public int GetIntValue()
     {
         int outValue = int.MinValue;
         int.TryParse(value, out outValue);
         return outValue;
     }
 
     public bool GetBoolValue()
     {
         bool outValue = false;
         bool.TryParse(value, out outValue);
         return outValue;
     }
 
     public void SetValue(string inValue)
     {
         value = inValue;
     }
 
     public void SetValue(float inValue)
     {
         value = inValue.ToString();
     }
 
     public void SetValue(int inValue)
     {
         value = inValue.ToString();
     }
 
     public void SetValue(bool inValue)
     {
         value = inValue.ToString();
     }
 }
 [Serializable]
 public class HardwareComponent
 {
     public string Identifier;
     public string Name;
     public string Description;
 
     [SerializeField]
     private List<ComponentProperty> properties;
 
     public List<ComponentProperty> Properties
     {
         get
         {
             if (properties == null)
                 properties = new List<ComponentProperty>();
             return properties;
         }
     }
 }
 
 [Serializable]
 public class JSONTest : MonoBehaviour
 {
     [SerializeField]
     public List<HardwareComponent> Components;
 
     // Use this for initialization
     void Start ()
     {
         Components = new List<HardwareComponent>();
         for (int i = 0; i < 10; i++)
         {
             HardwareComponent comp = new HardwareComponent();
             comp.Identifier = string.Format("Component_{0}", i);
             comp.Name = string.Format("Component {0}", i);
             comp.Description = "Dummy Description";
             ComponentProperty newProp = new ComponentProperty();
             newProp.Key = "String Property";
             newProp.Units = "kg";
             newProp.SetValue("A String");
             comp.Properties.Add(newProp);
             ComponentProperty newProp2 = new ComponentProperty();
             newProp2.Key = "Float Property";
             newProp2.Units = "m";
             newProp2.SetValue(1.14f);
             comp.Properties.Add(newProp2);
             // This will print out proper JSON including the list
             print(JsonUtility.ToJson(comp));
         }
         // This will generate an empty JSON object
         print(JsonUtility.ToJson(Components));
 
     }
 }
 

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

0 Replies

  • Sort: 

Follow this Question

Answers Answers and Comments

104 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

JsonUtility not making JSONs 1 Answer

Armed Unity Parkour 0 Answers

Recursive JSON serialization / serialize list of custom serializable objects? 1 Answer

Deserialize Json array with mixed types 0 Answers

j son file store the multiple image?image should be fetch in unity but how can i show a image in canvas drop down list?? 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