0

In my unity project I have Resources folder. I tried to create json file into Resources folder. But when I run the unity it says ArgumentException:..... I tried to use Application.dataPath .It successfully created in unity editor...in android it is not working. The reason why I use Resources Because I successfully read json file (which is already created) in android but I cannot create json file.

This is my simple Ciop.cs script

    using System.IO;
    using UnityEngine;
    using UnityEngine.UI;
    using LitJson;
    public class Ciop : MonoBehaviour {

        private JsonData itemData;
        private baaaaza nj;

        void Start () {

            nj = new baaaaza("eshhak");
            string jsn = Resources.Load<TextAsset>("Rr").text;
            itemData = JsonMapper.ToJson(nj);
            File.WriteAllText(jsn, itemData.ToString());
        }  
  }
    public class baaaaza
    {
        public string Name;
        public baaaaza(string name)
        {
            this.Name = name;
        }
    }
StepHan
  • 61
  • 2
  • 12
  • You can't write to the Resources folder during run-time. It is read-only and must be read with the [Resources](https://stackoverflow.com/questions/41326248/using-resources-folder-in-unity/41326276#41326276) API. For multiple-platform compatibly saving, save to `Application.persistentDataPath+"YourFolder"`...See the dup for an example. – Programmer Jul 16 '17 at 08:46
  • which is faster `playerprefs` or `json`? – StepHan Jul 16 '17 at 11:23
  • 1
    That doesn't really make sense when you compare playerprefs and json. playerprefs saves data. json does not save file. It serializes a class/data then `File.ReadAllBytes` is used to save it. Maybe you meant to compare playerprefs and File.ReadAllBytes? The speed of these shouldn't matter. Doesn't really make a difference. – Programmer Jul 16 '17 at 11:28
  • I think the best choice is `playerpref`. It is working on android well and very easy! I know it cannot be more than 1mb. – StepHan Jul 16 '17 at 12:16
  • I won't argue over the two. Use whatever suits you. – Programmer Jul 16 '17 at 12:18

0 Answers0