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 /
avatar image
0
Question by brianchan661 · Sep 07, 2015 at 03:48 PM · json

converting excel to json: reading problem when file too large

I have a excel file which stored my game data, and successfully converted to json file.
A sample on excel file and the converted json:
alt text
The pretty output on the sample data:
alt text While if the excel file contain a lot of data, which exceed the size of String can hold (I believe), problem on reading the json will exceed.

Hence I would like to ask how should my json file be wrote and read so I need not to care about the file( or string) size.

 //function that create the json object ( using Simple Json library in eclipse)
  public void createJson(String outputpath,XSSFSheet sheet){
         XSSFRow singleRow;
         XSSFCell cell;
         int totalRows=getExcelTotalRow(sheet);
         int totalCol=getExcelTotalColumn(sheet);
                 
         JSONObject jsonObject=new JSONObject();    
         
         String[] attributes=getJsonAttributes(sheet.getRow(0));
         
         for(int i=1; i<totalRows;i++){
             JSONObject jRow = new JSONObject();
             singleRow=sheet.getRow(i);
             String chipRoot="";
             for(int j=0;j<totalCol;j++){
                 cell=singleRow.getCell(j);
                 cell.setCellType(Cell.CELL_TYPE_STRING);
                 jRow.put(attributes[j], cell.toString());
                 if(j==0){
                     chipRoot=cell.toString();
                 }
             }
             jsonObject.put(chipRoot, jRow);
             System.out.print("\n");
         }
         
         
         Gson gson = new GsonBuilder().setPrettyPrinting().create();
         String jsonOutput = gson.toJson(jsonObject);
         System.out.println(jsonOutput);
         writeJsonFile(outputpath,jsonObject);
     }

 //and function to create the json file
 public void writeJsonFile(String fileName, JSONObject jsonObject){
         try {
             //System.out.println(jsonObject);
             fileName=fileName.replace(".txt", "2.txt");
             FileWriter fw= new FileWriter(fileName);
             BufferedWriter bw = new BufferedWriter(fw);
             jsonObject.writeJSONString(fw);
             bw.close();
         } catch (IOException e) {
             // TODO Auto-generated catch block
             e.printStackTrace();
         }
     }





The code for reading json in unity

 public class chipManager :MonoBehaviour {
 
     public string fileName;
     public string chipJson;
 
     public Dictionary<int, Chip> chipDictionary=new Dictionary<int, Chip>();
 
 
     void Start(){
         getChipData ();
         putAllChipToDictionary ();
         getChipByID (1);
         getChipByID (2);
         getChipByID (3);
         getChipByID (5);
     }
 
 
 
     public void getChipData(){
         try
         {
             string fileFullPath= Application.dataPath+"/textFiles/"+fileName;
             StreamReader theReader = new StreamReader(fileFullPath, Encoding.Default);
             chipJson=theReader.ReadToEnd();
             theReader.Close();
 
         }
         catch (Exception e)
         {
             Debug.Log(e);
         }
     }
 
     public void putAllChipToDictionary(){
         var N = JSON.Parse (chipJson);
         //Debug.Log (N.Count);
         for(int i=0;i<N.Count;i++){
             int id = N[i]["ChipID"].AsInt;
             string chipName = N[i]["Name"];
             int power = N[i]["Power"].AsInt;
             string desc = N[i]["Desc"];
             Chip tempChip= new Chip(id,chipName,power,desc);
             chipDictionary.Add(id, tempChip);
         }
     }
 
     public void getChipByID(int chipID){
         Debug.Log ("getting chip "+ chipID);
         Chip chipReturn= chipDictionary[chipID];
         Debug.Log (chipReturn.ToString ());
     }
 }


2015-09-07-232338.png (7.7 kB)
2015-09-07-231212.png (51.8 kB)
Comment
Add comment · Show 1
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 Baste · Sep 08, 2015 at 09:05 AM 0
Share

Why do you believe that the data is too large to read? What exactly is the problem you're running into? If we don't know if it's errors, missing data, wrong behaviour or your children rejecting your advice as your generations are simply too out of touch, we cannot help you.

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

28 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

Related Questions

Parsing JsonData throws error when value is null, what to do? 0 Answers

JSON-Serializer (Renewed open) 0 Answers

Whew, I'm stuffed! (Hunger Script) 1 Answer

C# - Read JSON 1 Answer

Application.ExternalCall Issue 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