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
1
Question by radiodario · May 16, 2017 at 05:04 PM · androidjsonstreamingassets

Loading JSON file from streamingAssets on android

Hi there.

I'm trying to load a list of country codes i have stored in the streamingAssets folder. I'm able to load it properly with iOS, but on android, using a WWW request, i am getting a JSON parse error. When I log the contents of the file to the console, i.e. www.text, I see the data gets cut off halfway.

Is this a limitation of the WWW class?

The file is valid json and loads just fine on iOS.

This is the code i'm using to load the file:

 public IEnumerator LoadCountryCodes() {
     string filePath = Path.Combine(Application.streamingAssetsPath, "CountryCodes.json");
     string dataAsJson;
     if (filePath.Contains ("://")) {
         WWW www = new WWW (filePath);
         yield return www;
         dataAsJson = www.text;
     } else {
         dataAsJson = File.ReadAllText(filePath); 
     }

     CountryCodes countryCodes = JsonUtility.FromJson<CountryCodes>(dataAsJson);

     if (OnCodesLoadedMethods != null) {
         OnCodesLoadedMethods (countryCodes.codes);
     }
 }
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 bluemike · May 22, 2017 at 06:57 AM 0
Share

Have you tried using the 'bytes' property ins$$anonymous$$d of 'text' ?

     byte[] dataAsBytes = www.bytes;
     string dataAsJson = System.Text.Encoding.Default.GetString (bytes);
 

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by radiodario · May 23, 2017 at 09:10 AM

Hey I loaded the file from Resources as a TextAsset and then converted it to JSON, and that worked

 public void LoadCountryCodes() {
     TextAsset codesJson = Resources.Load<TextAsset> ("CountryCodes");


     CountryCodes countryCodes = JsonUtility.FromJson<CountryCodes>(codesJson.text);
     Debug.Log ("Country codes loaded: " + countryCodes.codes.Length);
     if (OnCodesLoadedMethods != null) {
         OnCodesLoadedMethods (countryCodes.codes);
     }
 }

Thanks for your help @blue-mile

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 bluemike · May 23, 2017 at 12:27 PM 0
Share

Interesting. But it doesn't solve your problem in case you really want your JSON file to be a strea$$anonymous$$g asset ins$$anonymous$$d of a resource (a strea$$anonymous$$g asset could be split from binary on Android for example).

I wonder if this is an issue with the WWW.text property or with JsonUtility. Have you tried writing down WWW.text back into a file ? BTW, what is the size of your file ?

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

163 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

Related Questions

Loading JSON from StreamingAssets on android(c#) 0 Answers

Read and Write Textfile on mobile (C# Unity ) 0 Answers

Help Writing and reading files on android. 1 Answer

Ressource.Load returns null on "build" but work on "build and run" 2 Answers

Loading from streaming assets in obb fails.. but not always. 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