Retreiving Json Data don't Work on Android Devices

So here’s my LocalizationManager.cs

 IEnumerator Refresh_()
    {
        Debug.LogWarning("TODO: 로딩 팝업 on.");

        rh.eLanguage language = tzGlobal.Instance.OPTION.language;
       
        string json = StreetUtility.LoadJsonFromStreamingAssets("notice.json");
        if (json != null)
        {
            // 필요한 부분만 분리.
            LitJson.JsonData data = LitJson.JsonMapper.ToObject(json);
            json = data[language.ToString()].ToJson();
           
            notice = LitJson.JsonMapper.ToObject<string[]>(json);
        }

        string path = string.Format("{0}/{1}/language", rh.Const.LOCALIZATION_PATH, language);
        json = StreetUtility.LoadJsonFromResources(path);
        if (json != null)
        {
            // json 로드.
            Dictionary<string, string> dic = LitJson.JsonMapper.ToObject<Dictionary<string, string>>(json);

            // dictionary 카피.
            dic_localization_text = new Dictionary<eTextKey, string>();
            eTextKey e;
            for (int i = 0; i < dic.Count; i++)
            {
                e = (eTextKey)i;
                dic_localization_text[e] = dic[e.ToString()];
            }

            // 등록된 localize 함수 실행.
            for (int i = 0; i < list_localize_method.Count; i++)
            {
                complete = false;
                list_localize_method[i].Invoke();
                yield return new WaitUntil(() => complete);
            }
        }

        Debug.LogWarning("TODO: 로딩 팝업 off.");
    }

And here’s my StreetUtility.cs

 public static string LoadJsonFromStreamingAssets(string path_with_extention_under_streaming_assets_folder)
    {
        string json = null;
        try
        {
            //Android Platform
#if UNITY_ANDROID
            string oriPath = Path.Combine(Application.streamingAssetsPath, path_with_extention_under_streaming_assets_folder);

            WWW reader = new WWW(oriPath);
            while (!reader.isDone) { }
            string realPath = Application.persistentDataPath + "/" + path_with_extention_under_streaming_assets_folder;
            System.IO.File.WriteAllBytes(realPath, reader.bytes);

            path_with_extention_under_streaming_assets_folder = realPath;

#elif UNITY_IOS //IOS Platform
           
#elif UNITY_STANDALONE //PC Platform
            string full_path = string.Format("{0}/{1}", Application.streamingAssetsPath, path_with_extention_under_streaming_assets_folder);
            StreamReader reader = new StreamReader(full_path);
            json = reader.ReadToEnd().Trim();
            reader.Close();

            Debug.Log(json);
#endif
        }
        catch (Exception e)
        {
            Debug.LogWarningFormat("Failed to Load.\n{0}\n{1}", e, path_with_extention_under_streaming_assets_folder);
        }
        return json;
    }

and here is my .Json that is verified in https://jsonlint.com/ .

{
“EN”: [
“Cancel is available with Cancel button.”,
“If you succeed in a lottery, you can receive additional rewards.”,
“Round 2 and 3 are shorter than you think.”,
“Please check the homepage in Confirm Game Method and Change Member Information.”
],
“KR”: [
“Cancel 버튼으로 배팅 취소가 가능합니다.”,
“로또에 성공하면 추가적인 보상을 받을 수 있습니다.”,
“라운드 2와 3은 생각보다 시간이 짧습니다.”,
“게임 방법 확인 및 회원정보 변경은 홈페이지에서 확인해주세요.”
],
“CN”: [
“[中文] Cancel is available with Cancel button.”,
“[中文] If you succeed in a lottery, you can receive additional rewards.”,
“[中文] Round 2 and 3 are shorter than you think.”,
“[中文] Please check the homepage in Confirm Game Method and Change Member Information.”
],
“HK”: [
“[广东话] Cancel is available with Cancel button.”,
“[广东话] If you succeed in a lottery, you can receive additional rewards.”,
“[广东话] Round 2 and 3 are shorter than you think.”,
“[广东话] Please check the homepage in Confirm Game Method and Change Member Information.”
]
}

My problem here is that it’s not getting the file . Please someone please help me out with this one.

It’s not working because you aren’t setting json = to the string you get in the Android section of your code, so when you return json, it returns null.

What do you mean sir? i don’t quite understand

He means this line

string json = null;
///....
json = reader.ReadToEnd().Trim(); //THIS ONE

It is on your PC/Standalone compile section, but it isn’t on your Android section. So json will always be null.

My PC/Standalone is working fine . So should i do it also on my #if UNITY_ANDROID ? like this?

json = null;
while(!reader.isDone){}
json = reader.text;

Yeah

Thank you sir it’s actually working now what i did is like this

json = null;
while(!reader.isDone){}
json = reader.text.Trim();

1 Like