Realtime data with JSON,Realtime JSON updates
Hi, I'm new to Unity. I'm trying to build a simple app where I want to show realtime readings using JSON file. Here is the following code I am using. Unfortunately, the readings are not getting refreshed and it only shows the very first JSON value. How can I fix this to get realtime updates from my JSON file>?
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using SimpleJSON;
public class DataLoader : MonoBehaviour
{
string JsonDataString;
public string OriginalJsonSite;
public Text CountryName;
public Text Cityname;
IEnumerator Start ()
{
WWW readingsite = new WWW (OriginalJsonSite);
yield return readingsite;
if (string.IsNullOrEmpty (readingsite.error)) {
JsonDataString = readingsite.text;
}
JSONNode jsonNode = SimpleJSON.JSON.Parse (JsonDataString);
CountryName.text = jsonNode ["country"].ToString ().ToUpper();
Debug.Log (jsonNode ["country"]);
CityName.text = jsonNode ["city"].ToString ().ToUpper();
Debug.Log (jsonNode ["city"]);
}
}
,Hi, I'm a newbie to unity. I'm trying to build a simple application to show realtime updates from a JSON file. I'm not sure if I'm doing it correctly. My result seems to be not refreshing and gets stuck to the first value received from the JSON. This is the code I;'m using. Any help will be very much appreciated.
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using SimpleJSON;
public class DataLoader : MonoBehaviour
{
string JsonDataString;
public string OriginalJsonSite;
public Text CountryName;
public Text Cityname;
IEnumerator Start ()
{
WWW readingsite = new WWW (OriginalJsonSite);
yield return readingsite;
if (string.IsNullOrEmpty (readingsite.error)) {
JsonDataString = readingsite.text;
}
JSONNode jsonNode = SimpleJSON.JSON.Parse (JsonDataString);
CountryName.text = jsonNode ["country"].ToString ().ToUpper();
Debug.Log (jsonNode ["country"]);
CityName.text = jsonNode ["city"].ToString ().ToUpper();
Debug.Log (jsonNode ["city"]);
}
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612165330im_/https://answers.unity.com/themes/thub/images/avi.jpg)