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 /
avatar image
0
Question by Albert Ha · Jan 06, 2015 at 12:44 PM · androidjsondatapath

How to read json file in android game?

Hi there,

I have few set of data store in different json file in a folder.When my game run, it will select one of the json file and load the data into the game. I use streamReader and specific the file path for the game to read the file.

When i test the game in pc, it works fine. But when i run the game in my mobile phone which is android platform, the game cant read the data from the json file. After i search on internet, it seems the file location in pc and android are different so i have to make change on the file path setting.

I had try on Application.datapath, Application.persistentDataPath, www method and change the write access in build setting to external(sd card), but my game still cant read the data inside the json file on my phone.

May i know what is the correct way to do read file in android or do i miss out some step?

Thank you.

Below is my example code on how i read the json file and load data into game.

 void Start()
     {
         Instance = this;
         StreamReader readJson = new StreamReader(Application.persistentDataPath  + FoodMenu.foodname + ".json");
         response = readJson.ReadLine();
 
         JsonData Json = JsonMapper.ToObject(response);
         
         //Set Recipe Name
         recipeName = (string)Json["RecipeName"];
 
         //Set time 
         time = (int)Json["Time"];

Comment
Add comment · Show 2
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 Graham-Dunnett ♦♦ · Jan 06, 2015 at 12:44 PM 0
Share

How do you get the json files onto the device? And where do you put them?

avatar image Albert Ha · Jan 07, 2015 at 03:05 AM 0
Share

I already have few sample json files inside the game folder to do game testing.When i build the game into the apk, the json files are inside the apk file also.

i keep all the json file in a folder call JSON and put the folder inside the script folder.(i.e:Assets/script/JSON)

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by Kamuiyshirou · Jan 06, 2015 at 01:54 PM

Try this: You need to change the build settings for android. change configuration > write access to external (sd card).

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 Albert Ha · Jan 07, 2015 at 03:10 AM 0
Share

I already do the setting change like you say but still cant read the data inside the json file.(sorry if i not stated my setting change was for android in the post.)

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Android - Straight answer for accessing data via Application.dataPath 1 Answer

Json not recognized on Android 1 Answer

Can't Access AppData Folder from Unity 1 Answer

Cannot access JSON file from Streaming Assets in android build 1 Answer

Difference between Application.persistantDataPath Vs Application.dataPath 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