I’m trying to get JSON data from a server using the WWW class and IEnumerator.
I removed all mono behavior inheritance, tried to deserialize the json data to my class, but I end up with an error I’ve never seen before:
ArgumentException: JSON parse error: The document root must not follow by other values.
UnityEngine.JsonUtility.FromJson[T] (System.String json) (at C:/buildslave/unity/build/artifacts/generated/common/modules/JSONSerialize/JsonUtilityBindings.gen.cs:25)
LoadDatabase+c__Iterator0.MoveNext () (at Assets/Scripts/LoadDatabase.cs:42)
UnityEngine.SetupCoroutine.InvokeMoveNext (System.Collections.IEnumerator enumerator, System.IntPtr returnValueAddress) (at C:/buildslave/unity/build/Runtime/Export/Coroutines.cs:17)
I’m starting to wonder if the problem is that I’m using a CoRoutine. Could that be the case?
[System.Serializable]
public class VehicleIndex
{
public string ID{ get; set;}
public string Make{ get; set;}
public string Model{ get; set;}
public string Year{ get; set;}
public string Mileage{ get; set;}
}
Removed the constructor
[System.Serializable]
public class VehicleCollection
{
// public List <VehicleIndex>VehicleList{ get; set;}
public VehicleIndex[] vehicles;
}
Created a new class here.
Now the sticky point
public IEnumerator GetAllVehicles()
{
WWW VehicleData = new WWW ("http://localhost/CMVM/LoadVehicle.php");
yield return VehicleData;
Debug.Log (VehicleData.text);
This part shows all the JSON- all good
string json = VehicleData.text;
Not quite sure about this..
var cars = JsonUtility.FromJson<VehicleCollection>(json);
Can anyone give me a hand with this?
Thanks!