I am really struggling with getting JSON from a REST service. The JSON looks like this:
[{“ptid”:91,“latitude”:29.6224155426025,“longitude”:-95.7319641113281,“elevation”:0.0,“description”:“CL”,“type”:1,“aid”:1},{“ptid”:92,“latitude”:29.6223545074463,“longitude”:-95.7321014404297,“elevation”:0.0,“description”:“CL”,“type”:1,“aid”:1},{“ptid”:93,“latitude”:29.6223125457764,“longitude”:-95.7321701049805,“elevation”:0.0,“description”:“CL”,“type”:1,“aid”:1},{“ptid”:94,“latitude”:29.6222438812256,“longitude”:-95.732292175293,“elevation”:0.0,“description”:“CL”,“type”:1,“aid”:1},{“ptid”:95,“latitude”:29.6221942901611,“longitude”:-95.7323684692383,“elevation”:0.0,“description”:“CL”,“type”:1,“aid”:1},{“ptid”:96,“latitude”:29.6221351623535,“longitude”:-95.7324981689453,“elevation”:0.0,“description”:“CL”,“type”:1,“aid”:1},{“ptid”:97,“latitude”:29.6221008300781,“longitude”:-95.7326278686523,“elevation”:0.0,“description”:“CL”,“type”:1,“aid”:1},{“ptid”:98,“latitude”:29.6220836639404,“longitude”:-95.7327117919922,“elevation”:0.0,“description”:“CL”,“type”:1,“aid”:1},{“ptid”:99,“latitude”:29.6220645904541,“longitude”:-95.7328033447266,“elevation”:0.0,“description”:“CL”,“type”:1,“aid”:1}]
The code is like this:
public IEnumerator Get(string url,)
{
using (UnityWebRequest www = UnityWebRequest.Get(url))
{
www.chunkedTransfer = false;
yield return www.Send();
if (www.isNetworkError)
{
Debug.Log(www.error);![]()
}
else
{
if (www.isDone)
{
string jsonResult = System.Text.Encoding.UTF8.GetString(www.downloadHandler.data);![]()
string jsonResult = Encoding.Default.GetString(www.downloadHandler.data);![]()
SurveyPoint[ ] myObject = JsonUtility.FromJson<SurveyPoint[ ]>(jsonResult);
}
}
}
}
[Serializable]
public class SurveyPoint
{
public int ptid { get; set; }
public double latgitude { get; set; }
public double longitude { get; set; }
public double elevation { get; set; }
public string description { get; set; }
public int type { get; set; }
public int aid { get; set; }
}
The last line causes an error. The error is:JSON must represent an object type. I do not understand. Any help would really be appreciated