- Home /
sending the information to the database fails :C
ERROR
ArgumentException: JSON parse error: Invalid value. UnityEngine.JsonUtility.FromJson (System.String json, System.Type type) (at :0) UnityEngine.JsonUtility.FromJson[T] (System.String json) (at :0) NetworkManager+d__1.MoveNext () (at Assets/Script/NetworkManager.cs:29) UnityEngine.SetupCoroutine.InvokeMoveNext (System.Collections.IEnumerator enumerator, System.IntPtr returnValueAddress) (at :0)
Code
using System.Collections;
using System;
using UnityEngine;
using UnityEngine.Networking;
using UnityEngine.Experimental.Networking;
public class NetworkManager : MonoBehaviour
{
public void CreateUser(string userName, string email, string pass, Action<Response> response)
{
StartCoroutine(CO_CreateUser (userName, email, pass, response));
}
private IEnumerator CO_CreateUser(string userName, string email, string pass, Action<Response> response)
{
WWWForm form = new WWWForm();
form.AddField("userName", userName);
form.AddField("email", email);
form.AddField("password", pass);
UnityWebRequest www = UnityWebRequest.Post("http://localhost/Game/createUser.php", form);
www.downloadHandler = new DownloadHandlerBuffer();
yield return www.SendWebRequest();
response(JsonUtility.FromJson<Response>(www.downloadHandler.text));
}
}
[Serializable]
public class Response
{
public bool done = false;
public string message = "";
}
Answer by Bunny83 · Mar 03, 2020 at 12:27 AM
Well, the error is pretty clear. Whatever your createUser.php
script returns in www.downloadHandler.text
is not valid json. Have you actually tried to debug your issue? Have you tried printing what is returned from your script?
We can't tell what your PHP script returns since we don't know what that script does. Maybe it doesn't run properly and throws an exception and the returned text is just an error message and not the result you're waiting for.
However serverside scripting is out of scope of UnityAnswers. Apart from that we can't really answer anything since the important parts (the PHP script and / or the actual returned text) are missing.
Your answer
Follow this Question
Related Questions
system login and registration unity 0 Answers
how to retrive an array from SQL database in Javascript? 1 Answer
UnityWebRequest all response headers are null 4 Answers
Best Server Choice for Single Player Game 1 Answer
C# - Read JSON 1 Answer