Hi all,
I know this has been asked previously and I have looked through those post. I am having a hard time wrapping my brain around what I have to do to get an array to work with the JsonUtitlity Serialization, or if it’s even possible.
Heres what I have:
[System.Serializable]
public class JSONObject : System.Object {
public string[] values;
}
public void request (params string[] values){
JSONObject JSON = new JSONObject ();
JSON.values = values;
StartCoroutine(webCoro(JsonUtility.ToJson(JSON)));
}
void response (string JSONstring) {
JSONObject JSON = JsonUtility.FromJson <JSONObject> (JSONstring);
}
IEnumerator webCoro (string data){
string URL = "http://" + host + ":" + port;
WWW request = new WWW (URL, encoding.GetBytes (data));
while (!request.isDone) {
yield return null;
}
Debug.Log ("Request Error: " + request.error);
response (request.text);
}
public void test (){
request ("script", "action", "test");
}
When I run test () I get:
ArgumentException: JSON must represent an object type.
UnityEngine.JsonUtility.FromJson[JSONObject] (System.String json) (at C:/buildslave/unity/build/artifacts/generated/common/modules/JSONSerialize/JsonUtilityBindings.gen.cs:24)
Web.response (System.String JSONstring) (at Assets/Web.cs:36)
Web+c__Iterator0.MoveNext () (at Assets/Web.cs:50)
What do I need to do to make this happen?
Thanks in advance,
Sean