Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by fcojavierojeda7 · Feb 19 at 07:45 PM · programmingmysql

Error: JSON parse error: Invalid value.

First I apologize. I am using google translate to ask the question.

I am trying to make a logging system in a mysql database with unity. At the moment, the database is local. But when sending the data, or rather when receiving it, the following error occurs:

 ArgumentException: JSON parse error: Invalid value.
 UnityEngine.JsonUtility.FromJson (System.String json, System.Type type) (at <3e7f43c38e214491a21ee815b941dbb6>:0)
 UnityEngine.JsonUtility.FromJson[T] (System.String json) (at <3e7f43c38e214491a21ee815b941dbb6>:0)
 NetworkManager+<CO_CreateUser>d__1.MoveNext () (at Assets/Scripts/NetworkManager.cs:30)
 UnityEngine.SetupCoroutine.InvokeMoveNext (System.Collections.IEnumerator enumerator, System.IntPtr returnValueAddress) (at <9899854e5b05425ab27d31f737cde095>:0)


Registration should occur when the user presses a button. The method that is executed when the button is pressed is in a script called MainMenuController. The method is the following:

 public void SubmitRegistration(){
 
         if (nameCountrySelected == ""){
             UserError(3);
             return;
         }
 
         if(!EmptyInputField()){
             UserError(1);
             return;
         }
 
         if (inpPasswordRegistrationMenu.text != inpConfirmPasswordRegistrationMenu.text){
             UserError(2);
             return;
         }
 
         CommunicationMenu.SetActive(true);
 
         networkManager.CreateUser(inpNameRegistrationMenu.text, inpEmailRegistrationMenu.text, 
         inpPasswordRegistrationMenu.text, inpNickNameRegistrationMenu.text, nameCountrySelected, 
         delegate (Response response){
             txtComm.text = response.message;
         }
         );
     }


Where txt Comm.text is a TEXTFIELD that should display the message it receives. The script that the "Assets/Scripts/NetworkManager.cs:30" error refers to is as follows:

 public class NetworkManager : MonoBehaviour{
 
     public void CreateUser(string UserName, string email, string pass, string nickName, string country, Action <Response> response){
         
         StartCoroutine(CO_CreateUser(UserName, email, pass, nickName, country, response));
     }
 
     private IEnumerator CO_CreateUser(string UserName, string email, string pass, string nickName, string country, Action<Response> response){
 
         WWWForm form = new WWWForm();
         form.AddField("UserName", UserName);
         form.AddField("email", email);
         form.AddField("pass", pass);
         form.AddField("nickName", nickName);
         form.AddField("contry", country);
         
         UnityWebRequest www = UnityWebRequest.Post(GameConstants.URL_ADDRESS_CREATE_USER, form);
         yield return www.SendWebRequest();
 
         response(JsonUtility.FromJson<Response>(www.downloadHandler.text));
 
         if (www.result != UnityWebRequest.Result.Success) //www.result
         {   
             Debug.Log(www.error);
         }
         else 
         {
             Debug.Log("Form upload complete!");
         }
     }
 }
 
     [Serializable] public class Response{
     public bool done;
     public string message;
 }

It is on line 30 where the error occurs.

 response(JsonUtility.FromJson<Response>(www.downloadHandler.text));

The php code that is executed:

 <?php
 include "dbConnection.php";
 include "ConstantsFile.php";
 include "functions.php";
 
 $UserName = $_POST['UserName'];
 $email = $_POST['email'];
 $pass = hash("sha256", $_POST['pass']);
 $nickName = $_POST['nickName'];
 $contry = $_POST['contry'];
 
 
 $sql = "SELECT Name_User FROM users WHERE Name_User = '$UserName'"
 $result = $pdo->query($sql);
 
 if($result->rowCount() > 0){
   MessageAfterQuery(false, ERROR_NAME_USER);
   exit();
 }
 else{
   $sql = "SELECT Email_User FROM users WHERE Email_User = '$email'"
   $result = $pdo->query($sql);
 
   if($result->rowCount() > 0){
     MessageAfterQuery(false, ERROR_EMAIL);
     exit();
   }
 }
 else{
   $sql = "INSERT INTO users(Name_User, Email_User, Password_User,
   Nick_User, Country_User)
   VALUES ('[$UserName]','[$email]','[$pass]','[$nickName]','[$contry]')";
   $pdo->query($sql);
 
   MessageAfterQuery(true, CONFIRM_CREATE_USER);
   exit();
 }
 ?>

The function that must send the information in Json "MessageAfterQuery" is this:

 <?php
 include "ConstantsFile.php";
 
 $data ="";
 
 function MessageAfterQuery($boolConfirm, $messageQuery){
   $data = array('done'=> $boolConfirm, 'message'=> $messageQuery);
   Header('Content-Type: application/json');
   echo json_encode($data);
   exit();
 }
 ?>

I have searched the internet and I have tried different alternatives but I cannot solve this error.

I don't know what part of the code is wrong.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

150 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Hi,can someone please help me? What is wrong with my cs code?Unity say Assets/Typer.cs(24,17): error CS0029: Cannot implicitly convert type `UnityEngine.UI.Text' to `UnityEngine.Texture' 1 Answer

Target Wheel Rotation/Physics 0 Answers

Can someone help me fix this coding error? 1 Answer

What would be the best way to make large amounts of similar collectible objects (+600)? 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges