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 /
avatar image
0
Question by NanjaKilo · Mar 21, 2016 at 09:26 AM · pluginlistsdatajava to c#

LitJson: unknown LitJson and TypeInitialization Exception, invalid tokens

Database.cs

     using UnityEngine;
     using System.Collections;
     using System.Collections.Generic;
     using LitJson;
     using System.IO;
     
     public class Database : MonoBehaviour
     {
         //have temporarily silenced all Mech variables and dependant methods to troubleshoot, because I have populated a JSON mech list and not yet put in its type constructors or properties.
     
         public static List<Weapon> WeaponDatabase = JsonMapper.ToObject<List<Weapon>>(File.ReadAllText(Application.dataPath + "/Mechwarrior Remake/StreamingAssets/weapons.json"));
         //public static List<Mech> MechDatabase = JsonMapper.ToObject<List<<Mech>>(File.ReadAllText(Application.dataPath + "/Mechwarrior Remake/Streaming Assets/mechs.json"));
         public static List<Personnel> PersonnelDatabase = JsonMapper.ToObject<List<Personnel>>(File.ReadAllText(Application.dataPath + "/Mechwarrior Remake/Streaming Assets/personnel.json"));
         //variables that pull down and reads item data from Json files and returns info by index
         public static JsonData WeaponData = JsonMapper.ToObject(File.ReadAllText(Application.dataPath + "/Mechwarrior Remake/StreamingAssets/weapons.json"));
         public static JsonData MechData;
         public static JsonData PersonnelData = JsonMapper.ToObject(File.ReadAllText(Application.dataPath + "/Mechwarrior Remake/Streaming Assets/personnel.json"));
     
         //matches database item ID to a searched integer then returns item. 
         public static Weapon W_FetchItemById(int id)
         {
             for (int i = 0; i < WeaponData.Count; i++)
             {
                 if (WeaponDatabase[i].ID == id)
                 {
                     return WeaponDatabase[i];
                 }
                 Debug.Log("Weapon ID Fetcher could not find database info and failed to create Weapons");
             }
             Debug.Log("Weapon ID Fetcher failed to construct");
             return null;
         }
     
         /*public static Mech M_FetchItemById(int id)
         {
             for (int i = 0; i < MechData.Count; i++)
             {
                 if (MechDatabase[i].ID == id)
                 {
                     return MechDatabase[i];
                 }
                 Debug.Log("Mech ID Fetcher could not find database info and failed to create Mechs");
             }
             Debug.Log("Mech ID Fetcher failed to construct");
             return null;
         }*/
     
         public static Personnel P_FetchItemById(int id)
         {
             for (int i = 0; i < PersonnelData.Count; i++)
             {
                 if (PersonnelDatabase[i].ID == id)
                 {
                     return PersonnelDatabase[i];
                 }
                 Debug.Log("Personnel ID Fetcher could not find database info and failed to create Personnel");
             }
             Debug.Log("Personnel ID Fetcher failed to construct");
             return null;
         }
     }
     
     // item types
     public class Weapon
     {
         public int ID { get; set; }
         public string Title { get; set; }
         public string Type { get; set;}
         public int Cost { get; set;}
         public int Ammo { get; set;}
         public int Damage { get; set;}
         public int Heat { get; set;}
         public int Range { get; set;}
         public int ReloadTime { get; set;}
         public int Weight { get; set;}
         public string Description { get; set;}
         public bool Stackable { get; set;}
         public string Slug { get; set;}
         public Sprite Sprite { get; set;}
     
         public Weapon(int id, string title, string type, int cost, int ammo)
         {
             this.ID = id;
             this.Title = title;
             this.Type = Type;
             this.Cost = cost;
             this.Ammo = ammo;
         }
     
         public Weapon()
         {
             this.ID = -1;
         }
     }
     
     
     public class Mech
     {
         public int ID { get; set; }
         public string Title { get; set; }
     
         public Mech(int id, string title)
         {
                 this.ID = id;
                 this.Title = title;
                 
         }
     
         public Mech()
         {
             this.ID = -1;
         }
     }
     
         public class Personnel
         {
             public int ID { get; set; }
             public string Title { get; set; }
     
             public Personnel(int id, string title)
             {
                 this.ID = id;
                 this.Title = title;
             }
     
             public Personnel()
             {
                 this.ID = -1;
             }
         }
 

weapons.json

     [
       {
         "id": 0,
         "title": "Machine Gun Array",
         "type": "energy",
         "cost": 100,
         "stat": 
         {
           "ammo": 10,
           "damage": 1,
           "heat": 1,
           "range": 100,
           "reloadtime": 1,
           "weight": 1
         }
         "description": "a sample weapon",
         "stackable": true,
         "slug": "machine_gun_array"
       }
     ]
     

WeaponInventory.cs

     using UnityEngine;
     using UnityEngine.UI;
     using System.Collections;
     using System.Collections.Generic;
     
     public class WeaponInventory : MonoBehaviour
     {
         public static List<Weapon> WeaponInventoryStock = new List<Weapon>();
     
         void WeaponInventoryPrint()
         {
             for (int i = 0; i < Database.WeaponDatabase.Count; i++)
             {
                 WeaponInventoryStock.Add(new Weapon((int)Database.WeaponData[i]["id"], Database.WeaponData[i]["title"].ToString(), Database.WeaponData[i]["type"].ToString(), 
                                                     (int)Database.WeaponData[i]["cost"], (int)Database.WeaponData[i]["ammo"]));
             }
         }
     
         //Item UI
         //variables for establishing the parents gameobjects under which on-UI items will stack
         GameObject WeaponInventoryStack;
     
         //open variables were you drag and drop prefabs for UI items
         public GameObject GO_Weapon;
         public GameObject Slot_Weapon;
     
         //all lists and variables actually required to perform on-UI database construction
         int WeaponInventorySlotCount;
         public List<Weapon> ParsedWeapon = new List<Weapon>();
         public List<GameObject> WeaponInventorySlot = new List<GameObject>();
     
         void Start()
         {
             WeaponInventoryPrint();
             //construct Inventory UI Weapons
             WeaponInventorySlotCount = Database.WeaponDatabase.Count;
             WeaponInventoryStack = GameObject.Find("InventoryWeaponsShoppingQueue").transform.gameObject;
             for (int i = 0; i < WeaponInventorySlotCount; i++)
             {
                 ParsedWeapon.Add(new Weapon());
                 WeaponInventorySlot.Add(Instantiate(Slot_Weapon));
                 WeaponInventorySlot[i].transform.SetParent(WeaponInventoryStack.transform);
                 AddWeapon(i);
             }
             GameObject.Find("InventoryWeaponsShoppingQueue").SetActive(false);
         }
     
         public void AddWeapon(int id)
         {
             Weapon WeaponBeingAdded = Database.W_FetchItemById(id);
     
             if (ParsedWeapon[id].ID == -1)
             {
                 ParsedWeapon[id] = WeaponBeingAdded;
                 GameObject WeaponUIObject = Instantiate(GO_Weapon);
                 WeaponUIObject.name = WeaponBeingAdded.Title;
                 WeaponUIObject.transform.SetParent(WeaponInventorySlot[id].transform);
                 WeaponUIObject.GetComponent<Image>();
             }
     
         }
     }

I am having issues with what my guess would be serializing data between my JSON files and my actual scripts that are dependant on them to assemble lists. I've looked at roundabout ways of parsing the JSON data in for loops and what not (perhaps not hard enough), but no matter what I try and after checking my JSON data for misplaced commas or type errors, the same error keeps appearing. It doesn't seem to be a typical "Read() error" and I've found nothing online for support with a token 34 error. I'm just gonna need help from someone who knows about the LitJson plugin way more than I do, to even understand where the problem is let alone fix it.

Console Message

Thanks in advance, sorry for the novel...

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

· Add your reply
  • Sort: 

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

LitJson: unknown JSON and TypeInstantiation Exceptions, invalid tokens 0 Answers

Spawn unique objects from the array 1 Answer

get the total valor float inside a Gameobject from a List 1 Answer

Can someone help me please? 0 Answers

DLLNotFoundException when trying to import Firebase project 2 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