Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Json Parse Error Unity

Discussion in 'Getting Started' started by crouseoper, Aug 16, 2023.

?

Json Parse Error

  1. Json

    0 vote(s)
    0.0%
  2. Json.Utilty

    1 vote(s)
    100.0%
Multiple votes are allowed.
  1. crouseoper

    crouseoper

    Joined:
    Apr 23, 2021
    Posts:
    1
    Code (CSharp):
    1. IEnumerator Login()
    2.     {
    3.         WWWForm form = new WWWForm();
    4.         form.AddField("action", "login");
    5.         form.AddField("_nickname", Nickname_IF_Log.text);
    6.         form.AddField("_email", Email_IF_Log.text);
    7.         form.AddField("_password", Password_IF_Log.text);
    8.  
    9.         using (UnityWebRequest www = UnityWebRequest.Post("http://localhost:8080/cosmicorigins/login.php", form))
    10.         {
    11.             yield return www.SendWebRequest();
    12.  
    13.             if (www.result != UnityWebRequest.Result.Success)
    14.             {
    15.                 Debug.Log(www.error);
    16.             }
    17.             else
    18.             {
    19.                 Debug.Log("Query Result:" + www.downloadHandler.text);
    20.  
    21.                AuthResult authResult = JsonUtility.FromJson<AuthResult>(www.downloadHandler.text); (cs:271)
    22.  
    23.                 if (authResult.status)
    24.                 {
    25.                     PlayerPrefs.SetInt("ID", authResult._id);
    26.  
    27.                     Password_IF_Log.text = "";
    28.                     Email_IF_Log.text = "";
    29.                     Nickname_IF_Log.text = "";
    30.                     Message_Warning_Log.text = "Login Successfully!";
    31.                     ProggressBar.gameObject.SetActive(true);
    32.                     StartCoroutine(LoadingCharacterCustomizedScene());
    33.                     StartCoroutine(Loginsuccessfullyfalse());
    34.                 }
    35.                 else
    36.                 {
    37.  
    38.                     StartCoroutine(Loginsuccessfullyfalse());
    39.                 }
    40.             }
    41.         }
    42.     }
    43. }
    ============================================================================

    **Hello, I have the following C# code and I'm encountering a JSON parse error. I would greatly appreciate your assistance in resolving this issue. The error message is provided below:

    ============================================================================
    ArgumentException: JSON parse error: Invalid value.
    UnityEngine.JsonUtility.FromJson (System.String json, System.Type type) (at <9022f24b5f99402395bd0f17ce2ed626>:0)
    UnityEngine.JsonUtility.FromJson[T] (System.String json) (at <9022f24b5f99402395bd0f17ce2ed626>:0)
    AuthManager+<Login>d__33.MoveNext () (at Assets/Scripts/AuthManager.cs:271)
    UnityEngine.SetupCoroutine.InvokeMoveNext (System.Collections.IEnumerator enumerator, System.IntPtr returnValueAddress) (at <4014a86cbefb4944b2b6c9211c8fd2fc>:0)

    =============================================================================

    **I've indicated the part where the error occurs in the code within quotation marks.
     
  2. AngryProgrammer

    AngryProgrammer

    Joined:
    Jun 4, 2019
    Posts:
    490
    You could post at least a JSON example. That you have a parse error is no information at all. At this stage I can only tell that you can have wrong JSON or wrong AuthResult.