So today I'm stuck trying to wrap my head around JSON and all the magic around it,
I have two scripts:
JsonDataClass (Used to define classes)
[Serializable]
public class JsonDataClass
{
public List<DataList> data;
public int code;
}
[Serializable]
public class DataList
{
public string priceCOIN;
public string currency;
}
JsonController (Used to fetch info)
public class JsonController : MonoBehaviour
{
public string jsonURL = "https://www.enter.art/api/FetchNFTPricing?walletAddress=0xCA3B0f72ae4fB4841F669614Ffc421c0ED68b943&tokenId=35237";
public void Start()
{
StartCoroutine(GetData());
}
IEnumerator GetData()
{
Debug.Log("Processing Data...");
WWW _www = new WWW(jsonURL);
yield return _www;
if (_www.error == null)
{
processJsonData(_www.text);
}
else
{
Debug.Log("Oops, we were unable to retrieve the data");
}
}
public void processJsonData(string _url)
{
JsonDataClass jsnData = JsonUtility.FromJson<JsonDataClass>(_url);
Debug.Log(jsnData.code);
foreach (DataList x in jsnData.data)
{
Debug.Log(x.currency);
}
}
}
In the JsonController script the jsnData.code gets logged as 200.
However it seems I can't serialize the list of Data as it never gets logged?
I want to think I have my classes correct and that everything should work, but it's not.
Any help would with this would be greatly appreciated. Ready to throw myself through a window.