In my # UNITY_STANDALONE
this line of code can read my json file and i do it like this
Define_ConstantValue.cs
#if UNITY_STANDALONE
string path = string.Format("{0}/datacenter.json", Application.streamingAssetsPath);
if (File.Exists(path)) {
StreamReader reader = new StreamReader(path);
try
{
CheckJSonManager.Instance._DataCenterJson = LitJson.JsonMapper.ToObject<DataCenterJson>(reader.ReadToEnd().Trim());
DataCenter_BaseURL = CheckJSonManager.Instance._DataCenterJson.dataCenter;
}
catch (Exception ex)
{
Debug.LogError("path : " + path + "\n" + ex);
}
reader.Close();
}
// (Get dealer server connection information) 딜러서버 접속 정보를 가져온다.
// (If the json file below is present, 'I am a dealer console) 아래 json파일이 존재하면, '나는 딜러콘솔이다'
path = string.Format("{0}/dealerserver.json", Application.streamingAssetsPath);
if (File.Exists(path))
{
StreamReader reader = new StreamReader(path);
try
{
Debug.Log("********************* DealerServer.JSON ***************************");
CheckJSonManager.Instance._DealerServerJson = LitJson.JsonMapper.ToObject<DealerServerJson>(reader.ReadToEnd().Trim());
}
catch (Exception ex)
{
Debug.LogError("path : " + path + "\n" + ex);
}
reader.Close();
}
else
{
CheckJSonManager.Instance._DealerServerJson = new DealerServerJson();
}
// (Server list URL) 서버리스트 URL.
serverListJsonURL = string.Format("{0}/pc_version/ph/check/serverList.json", DataCenter_BaseURL);
NOTICE_URL = string.Format("{0}/pc_version/ph/check/notice.json", DataCenter_BaseURL);
#endif
And displaying it like this in my
LogoUI.cs
// URL을 로드한다 ( Load the URL ).
CheckJSonManager.Instance._AwsDatacenterURL.SetURL();
// notice를 다운로드한다 ( download 'notice.json ).
WWW www = new WWW(CheckJSonManager.Instance._AwsDatacenterURL.NOTICE_URL);
yield return www;
//Debug PK 12/13/2017
Debug.Log("www notice url = " + CheckJSonManager.Instance._AwsDatacenterURL.NOTICE_URL);
// notice를 저장한다. ( save 'notice.json' )
StreetUtility.SaveJson_mk2(www.text, string.Format("{0}/notice.json", Application.streamingAssetsPath));
// (Download server list) 서버 리스트를 다운로드한다.
www = new WWW(CheckJSonManager.Instance._AwsDatacenterURL.SERVERLIST_URL);
yield return www;
Debug.Log("www serverlist url = " + CheckJSonManager.Instance._AwsDatacenterURL.SERVERLIST_URL);
Now this code returns a value of
www notice url = https://*********-***.amazonaws.com/pc_version/ph/check/notice.json
www serverlist url = https://*******-****.amazonaws.com/pc_version/ph/check/serverList.json
Now my problem occurs here in my # UNITY_ANDROID
line of code because it can't read my the json file from my streamingasset path. here's my code:
#if UNITY_ANDROID
string path = "jar:file://" + Application.dataPath + "!/assets/datacenter.json";
//string dataAsJson;
if (File.Exists(path)) {
WWW reader = new WWW(path);
while (!reader.isDone) ;
string filePath = string.Format("{0}/{1}", Application.persistentDataPath, "datacenter.json");
File.WriteAllBytes(filePath, reader.bytes);
//byte[] dataAsBytes = reader.bytes;
//dataAsJson = System.Text.Encoding.Default.GetString(dataAsBytes);
StreamReader wr = new StreamReader(filePath);
string line;
while ((line = wr.ReadLine())!= null)
{
try
{
CheckJSonManager.Instance._DataCenterJson = LitJson.JsonMapper.ToObject<DataCenterJson>(reader.text);
DataCenter_BaseURL = CheckJSonManager.Instance._DataCenterJson.dataCenter;
}
catch (Exception ex)
{
Debug.LogError("Path : " + path + "\n" + ex);
}
}
}
path = "jar:file://" + Application.dataPath + "!/assets/dealerserver.json";
if (File.Exists(path))
{
WWW reader = new WWW(path);
while (!reader.isDone) { }
string filePath = string.Format("{0}/{1}", Application.persistentDataPath, "dealerserver.json");
File.WriteAllBytes(filePath, reader.bytes);
//byte[] dataAsBytes = reader.bytes;
//dataAsJson = System.Text.Encoding.Default.GetString(dataAsBytes);
StreamReader wr = new StreamReader(filePath);
string line;
while ((line = wr.ReadLine()) != null)
{
try
{
Debug.Log("************************* DealerServer.JSON *************************");
CheckJSonManager.Instance._DealerServerJson = LitJson.JsonMapper.ToObject<DealerServerJson>(reader.text);
}
catch (Exception ex)
{
Debug.LogError("Path : " + path + "\n" + ex);
}
}
} else
{
CheckJSonManager.Instance._DealerServerJson = new DealerServerJson();
}
serverListJsonURL = string.Format("{0}/pc_version/ph/check/serverList.json", DataCenter_BaseURL);
NOTICE_URL = string.Format("{0}/pc_version/ph/check/notice.json", DataCenter_BaseURL);
#endif
and i call it the same on the #LogoUI.cs
and it returns a value of
www serverlist url = /pc_version/ph/check/serverList.json
www notice url = /pc_version/ph/check/notice.json
I guess this line of code doesn't work on android?
serverListJsonURL = string.Format("{0}/pc_version/ph/check/serverList.json", DataCenter_BaseURL);
NOTICE_URL = string.Format("{0}/pc_version/ph/check/notice.json", DataCenter_BaseURL);
UPDATE :
When I build my project as .apk and debug it with logcat, I am not getting the same result as # UNITY_STANDALONE
in # UNITY_ANDROID
.
In my
# UNITY_STANDALONE
it can get this value
www notice url = https://*********-***.amazonaws.com/pc_version/ph/check/notice.json
www serverlist url = https://*******-****.amazonaws.com/pc_version/ph/check/serverList.json
while on my
# UNITY_ANDROID
it doesn't return my this value which is it is on my datacenter.json
www serverlist url = /pc_version/ph/check/serverList.json
www notice url = /pc_version/ph/check/notice.json
it should return the notice url and serverlist url a value like this
www notice url = https://*********-***.amazonaws.com/pc_version/ph/check/notice.json
www serverlist url = https://*******-****.amazonaws.com/pc_version/ph/check/serverList.json