Esempio n. 1
0
    private void GetJsonData()
    {
        locationList = new LocationList();

        /*
         * var assembly = Assembly.GetExecutingAssembly();
         * string[] names = assembly.GetManifestResourceNames();
         * foreach (var name in names) Debug.Log(name);
         */
        // Solution1

        /*
         * string jsonFileName = "JsonData.json";
         * LocationList ObjContactList = new LocationList();
         * var assembly = Assembly.GetExecutingAssembly();
         * Debug.Log($"{assembly.GetName().Name}.Data.{jsonFileName}");
         * using(Stream stream = assembly.GetManifestResourceStream($"{assembly.GetName().Name}.Data.{jsonFileName}"))
         * using (var reader = new StreamReader(stream))
         * {
         *  var jsonString = reader.ReadToEnd();
         *  Debug.Log(jsonString);
         *  //Converting JSON Array Objects into generic list
         *  locationList = JsonConvert.DeserializeObject<LocationList>(jsonString);
         *  Debug.Log(locationList.data.Count);
         * }
         */
        // Solution2

        using (StreamReader r = new StreamReader("./Data/JsonData.json"))
        {
            string json = r.ReadToEnd();
            locationList = JsonConvert.DeserializeObject <LocationList>(json);
        }

        // Solution3

        /*
         * TextAsset file = Resources.Load("JsonData") as TextAsset;
         * string json = file.ToString();
         * locationList = JsonConvert.DeserializeObject<LocationList>(json);
         */

        locationProvinces = new List <LocationProvince>();
        for (int i = 0; i < locationList.data.Count; i++)
        {
            LocationProvince newLocationProvince = new LocationProvince();
            newLocationProvince.location = locationList.data[i];

            // Set province name
            string[] province = new string[2];
            province = Page_Load(float.Parse(locationList.data[i].latitude), float.Parse(locationList.data[i].longtitude));
            newLocationProvince.provinceNameThai = province[0];
            newLocationProvince.provinceNameEng  = province[1];

            locationProvinces.Add(newLocationProvince);
        }
        Debug.Log(locationProvinces.Count);
    }
Esempio n. 2
0
 public void SetLocation(LocationProvince newLocationProvince)
 {
     locationProvince  = newLocationProvince;
     provinceText.text = "จังหวัด" + newLocationProvince.provinceNameThai;
     locationText.text = newLocationProvince.location.placeNameThai;
 }