I'm trying to simply serialize a object into json in Unity. I have found several articles on this topic but nothing seems to be working. It is not throwing a exception directly but it is not converting the object to a json string. I have researched the pretty heavily and tried various samples. I'm not sure if the issue is the class or the logic calling the convert to json. I can easily convert using .net but this is for Unity in MonoScript, so the process seems to be a little different. I assume when you convert the object to json string it should not list the base as "null". Its also passing in a empty json string after conversion.
User LogIn Class:
using UnityEngine;
using System.Collections;
using System;
[Serializable]
public class UserLogIn : MonoBehaviour
{
public string Email;
public string Password;
}
Here is my code in unity script:
private UserLogIn _LogIn = new UserLogIn();
public void SetText(string text)
{
//[SerializeField]
//UserLogIn _LogIn = new UserLogIn();
//WhiteBoxGamingTestRequest();
_LogIn.Email = "testemail@gmail.com";
_LogIn.Password = "12345";
string json = JsonUtility.ToJson(_LogIn);
Debug.Log(json);
//User_LogIn(_login);
//text = _bolResponse.ToString();
//Text txt = transform.Find("Text").GetComponent<Text>();
//txt.text = text;
}
I've tried this: Serialize and Deserialize Json and Json Array in Unity
seems to not work still. Looking for suggestions or corrections.
After conversion json = {} it should be a string containing values. Is Unity's json converter broken?