Here's my script:
IEnumerator Refresh_()
{
Debug.LogWarning("TODO: Loading Popup on.");
rh.eLanguage language = tzGlobal.Instance.OPTION.language;
string json = StreetUtility.LoadJsonFromStreamingAssets("notice.json");
if (json != null)
{
// Separate only the necessary parts.
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 load.
Dictionary<string, string> dic = LitJson.JsonMapper.ToObject<Dictionary<string, string>>(json);
// dictionary copy.
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()];
}
// Run registered localize function.
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: Loading Popup off.");
}
Now what is happening here is that it loads the notice.json file but then as the execution goes this error will pop out
Failed to Load. LitJson.JsonException: Invalid character '' in input string at LitJson.Lexer.NextToken () [0x00000] in :0 at LitJson.JsonReader.ReadToken () [0x00000] in :0 at LitJson.JsonReader.Read () [0x00000] in :0 at LitJson.JsonMapper.ReadValue (LitJson.WrapperFactory factory, LitJson.JsonReader reader) [0x00000] in :0 at LitJson.JsonMapper.ToWrapper (LitJson.WrapperFactory factory, System.String json) [0x00000] in :0 at LitJson.JsonMapper.ToObject (System.String json) [0x00000] in :0 at StreetUtility.LoadJsonFromStreamingAssets (System.String path_with_extention_under_streaming_assets_folder) [0x00000] in :0 notice.json
Here's my code of my LoadJsonFromStreamingAssets() that i uses of calling my notice.json :
public static string LoadJsonFromStreamingAssets(string path_with_extention_under_streaming_assets_folder)
{
string json = null;
try
{
//Android Platform
#if UNITY_ANDROID
string full_path = Path.Combine(Application.persistentDataPath, path_with_extention_under_streaming_assets_folder);
if (full_path.Contains("://") || full_path.Contains(":///"))
{
WWW www = new WWW(full_path);
while (!www.isDone) { }
json = www.text;
}
else
{
json = File.ReadAllText(full_path);
}
Debug.Log("Loaded File : " + json);
JsonData itemData = JsonMapper.ToObject(json);
#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 file
{
"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."
]
}
And i uses JsonLint for verifying my json file and yes it is valid. I don't know why it is happening . Could someone point out what's going on ?