Hello everyone,
i have been working with a coworker with json in dynamoDB. when i try to do a query, DynamoDB showme the next json
[
{
"n_request":"",
"posicion":"",
"velocidad":"",
"client_id":"r2",
"status":"free",
"PartitionKey":3.0
},
{
"n_request":"",
"posicion":"",
"velocidad":"",
"client_id":"r1",
"status":"free",
"PartitionKey":2.0
},
{
"n_request":"",
"posicion":"",
"velocidad":"",
"client_id":"c2",
"status":"free",
"PartitionKey":1.0
},
{
"n_request":"",
"posicion":"",
"velocidad":"",
"client_id":"c1",
"status":"free",
"PartitionKey":0.0
}
]
i do the deserialisation with one simple json and works. but when i try to deserialize this complex json i can’t. here are objects and C# code.
public class JsonObjects
{
public DockiData[] allDockiData;
}
[Serializable]
public class DockiData
{
public string n_request;
public string posicion;
public float velocidad;
public string client_id;
public string status;
public string PartitionKey;
public int posX, posY;
char[] deleteLetters = { '[', ']', ',' };
public void SplitPos()
{
string[] positions = posicion.Split(deleteLetters, 4, StringSplitOptions.None);
posX = int.Parse(positions[1]);
posY = int.Parse(positions[2]);
}
}
and in here i deserialize the json
IEnumerator RequestJson()
{
UnityWebRequest carInformation = UnityWebRequest.Get(url);
yield return carInformation.SendWebRequest();
if (carInformation.isHttpError || carInformation.isNetworkError)
{
Debug.Log(carInformation.error);
}
else
{
string json = carInformation.downloadHandler.text;
print(json);
clients = JsonUtility.FromJson<JsonObjects>(json);
}
}
when i run the project apear the next issue:
ArgumentException: JSON must represent an object type.
UnityEngine.JsonUtility.FromJson (System.String json, System.Type type) (at <0618d0873e03447096799ae90b4ad4f1>:0)
UnityEngine.JsonUtility.FromJson[T] (System.String json) (at <0618d0873e03447096799ae90b4ad4f1>:0)
JsonLoader+d__5.MoveNext () (at Assets/Scripts/JsonScripts/JsonLoader.cs:46)
UnityEngine.SetupCoroutine.InvokeMoveNext (System.Collections.IEnumerator enumerator, System.IntPtr returnValueAddress) (at :0)
thanks for your help and regards.