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 /
  • Help Room /
avatar image
0
Question by NataTooma · Sep 13, 2020 at 05:01 PM · arraysjsonloading fileparsing

How do I return a series of arrays from a SimpleJSON Object

I'm looking to Load (and later save) a variation of data from a SimpleJSON Object.

The data set has a finite number of entries for the final project. Here is a snippet from the JSON file:

 {
   "ZJEquipmentItems" :
   [
     {
       "Equip_Name" : "AR 01",
       "Equip_Level": "1",
       "Equip_Damage" : "100",
     },
     {
       "Equip_Name" : "AR 02",
       "Equip_Level": "0",
       "Equip_Damage" : "110",
     },
     {
       "Equip_Name" : "AR 03",
       "Equip_Level": "0",
       "Equip_Damage" : "115",
     },
   ]
 }

I want to return 3 Arrays or possibly Lists (not sure which approach makes the most sense).

ENames would be an array of Type string, ELevels would be an array of Type int, and EDamValues would be an array of Type float.

My LoadData calls that needs some love:

 public void LoadDataFromFile()
     {
         string path = "Assets/_TempData/ZJEquipmentData.json";
         string jsonString = File.ReadAllText(path);
         JSONObject inventoryJson = (JSONObject)JSON.Parse(jsonString);
 
 STUCK HERE
 }

Any recommendations?

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
Best Answer

Answer by NataTooma · Sep 13, 2020 at 11:51 PM

Here is how I finally worked it all out, in case anyone else is looking for this information.

 using UnityEngine;
 using System.IO;
 using SimpleJSON;
 
 public class EquipmentData : MonoBehaviour
 {
     public TextAsset jsonAsset;
     public string[] Equip_Names;
     public string Equip_Name;
     public int[] Equip_Levels;
     public int Equip_Level;
     public float[] Equip_DamValues;
     public float Equip_Damage;
     public float[] Equip_RangeValues;
     public float Equip_Range;
 
   
     public void Load_JSON_Equipment_Data()
     {
         string path = "Assets/_TempData/EquipmentData.json";
         string jsonString = File.ReadAllText(path);
         JSONObject inventoryJSON = (JSONObject)JSON.Parse(jsonString);
         JSONNode node;
 
         for (int i = 0; i < Equip_Names.Length; i++)
         {
             node = inventoryJSON["ZJEquipmentItems"];
             Equip_Names[i] = node[i]["Equip_Name"];
             Equip_Levels[i] = node[i]["Equip_Level"];
             Equip_DamValues[i] = node[i]["Equip_Damage"];
             Equip_RangeValues[i] = node[i]["Equip_Range"];
         } 
     }
   
 }





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 NataTooma · Sep 14, 2020 at 01:47 AM 0
Share

$$anonymous$$ake sure to initialize the size of each array.

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

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

Related Questions

File.ReadAllBytes() returns byte[0] 0 Answers

Array not working properly 0 Answers

Location for files in order to be able to load them on Android 2 Answers

JSON parse error 0 Answers

[Error:] Cannot Deserialize JSON to new instances of type ' X ' 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