I'm trying to download json from the web and parse it then get the data and store it, however when i get the json from the server, i can't parse it as it's returning null for some values although it does have a value, and when i try to get specific data it returns actual null error. Now i know this question has been asked a lot of times. and i did search and tried many solutions however nothing seemed to work for me... I have used json to cshap to generate my json class in order to store the data in jsoncsharp Link
Here's the json that i download
{
"status": "success",
"result": {
"slug": "test",
"id": "26",
"timer_1": "15",
"timer_2": "10",
"pass_1": "aaaa",
"pass_2": "bbbb",
"count": "4",
"port": "66",
"network": "*******************",
"network2": "******************",
"network_api_consumer_key": "******************",
"network_api_consumer_secret": "******************",
"network_api_user_access_token": "******************",
"network_api_user_access_secret": "******************"
}
}
and here's the class where i store the values. this is generated by jsoncsharp
[System.Serializable]
public class Result
{
public string slug { get; set; }
public string id { get; set; }
public string timer_1 { get; set; }
public string timer_2 { get; set; }
public string pass_1 { get; set; }
public string pass_2 { get; set; }
public string count { get; set; }
public string port { get; set; }
public string network { get; set; }
public string network2 { get; set; }
public string network_api_consumer_key { get; set; }
public string network_api_consumer_secret { get; set; }
public string network_api_user_access_token { get; set; }
public string network_api_user_access_secret { get; set; }
}
[System.Serializable]
public class root
{
public string status { get; set; }
public Result result { get; set; }
}
and this is my method when i download
IEnumerator Fetch(string url)
{
UnityWebRequest www = UnityWebRequest.Get(url);
yield return www.SendWebRequest();
if (www.isNetworkError || www.isHttpError)
{
Debug.Log(www.error);
}
else
{
// Show results as text
Debug.Log(www.downloadHandler.text);
string jsonString = www.downloadHandler.text;
root data = JsonUtility.FromJson<root>(jsonString);
Debug.Log(data.status); //returns text null
Debug.Log(data.result.port); // returns actual null error
}
}
Thank you.