Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

704
Views
Deserializar JSON usando UnityEngine.JsonUtility devuelve una lista nula

Estoy tratando de modificar un juego de Unity usando BepInEx. Quiero leer una lista de un tipo de clase que he creado a partir de un JSON, luego leer cada objeto de esa clase. Usé UnityEngine.JsonUtility para hacer esto y creé una clase contenedora que contenía mi lista.

 [System.Serializable] public class StarSignDataList { public List<StarSignData> starSigns; } // Stores all data pertaining to star signs as read from JSON file. [System.Serializable] public class StarSignData { public string name; public int id; public string description; }

Luego leí el archivo json de la ruta de archivo correcta, analicé esa información en una cadena y llamé al método JsonUtility.FromJason() para convertir la cadena en mi clase StarSignDataList.

 // Reads all star sign data from JSON and assigns values to list. public static void InitializeData() { log.LogInfo("Initializing Star Sign data."); string json = File.ReadAllText("BepInEx/plugins/StarSigns/starsigns.json"); log.LogInfo(json); StarSignDataList list = UnityEngine.JsonUtility.FromJson<StarSignDataList>(json); log.LogWarning(list.starSigns.Count == 0 ? "Not null" : "Null!"); log.LogInfo(list.starSigns[0].name); signs = list.starSigns; foreach (StarSignData data in signs) { log.LogInfo(data.name); } }

Cuando imprimo el contenido de mi json inmediatamente después de leerlo, sale como se esperaba, luciendo exactamente como mi archivo json. Sin embargo, cuando convierto la cadena json en mi clase de lista, la lista está completamente vacía y luego arroja una NullReferenceException cuando intento imprimir el primer objeto. Intenté usar matrices en lugar de listas, verifiqué que mi json esté escrito correctamente, analicé innumerables resultados de búsqueda de Google sin éxito.

Aquí está mi archivo json.

 { "starSigns": [ { "name": "Sign of the Fool", "id": 0, "description": "You are of normal birth." }, { "name": "Sign of Loki", "id": 1, "description": "The sign of the god of betrayal shone above your birth place." }, { "name": "Sign of Odin", "id": 2, "description": "A tumultuous child at birth, your muscles bear the strength of Odin himself." } ] }

Por desesperación, intenté convertir una clase como esta en un json, y simplemente escribió en el archivo "{}". Cuando trato de hacer lo mismo solo con mi clase StarSignData, funciona como se esperaba, pero necesito colocar varios objetos en mi json y la clase de lista no parece funcionar. Tampoco puedo usar bibliotecas externas como SimpleJson para esto.

over 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!