Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- using UnityEngine.UI;
- using System.Web.Script.Serialization;
- using Newtonsoft.Json;
- namespace JavaScriptSerialization
- {
- public class LoginDB : MonoBehaviour {
- public static string user = "";
- private string password = "", id = "";
- public InputField loginInput;
- public InputField passInput;
- public Text text;
- public int _id;
- public void Update()
- {
- Users us = new Users();
- _id = us.id;
- }
- public void toReg()
- {
- Application.LoadLevel("Regist");
- }
- [System.Serializable]
- public class Users
- {
- public int id { get; set; }
- public string name { get; set; }
- public string klass { get; set; }
- public int gold { get; set; }
- public int exp { get; set; }
- public int level { get; set; }
- public override string ToString()
- {
- return string.Format("id: {0} \name: {1}", id, name);
- }
- }
- public void Login()
- {
- //message = "";
- user = loginInput.text.ToString ();
- password = passInput.text.ToString ();
- if (user == "" || password == "")
- text.text = "Please enter all the fields \n";
- else
- {
- WWWForm form = new WWWForm();
- form.AddField("email", user);
- form.AddField("password", password);
- WWW www = new WWW("http://uo.cx.ua/api/auth/login", form);
- StartCoroutine(login(www));
- }
- }
- IEnumerator login(WWW www)
- {
- yield return www;
- if (www.error != null)
- {
- Debug.Log ("error " + www.error);
- }
- else
- {
- string json = www.text; // <---{"users":{"id":1,"name":"","klass":"","gold":0,"exp":0,"level":1}}
- JavaScriptSerializer ser = new JavaScriptSerializer();
- Users us = ser.Deserialize<Users>(json);
- Users us2 = JsonConvert.DeserializeObject<Users>(json);
- Debug.Log (us.id);
- Debug.Log(us2.id);
- Debug.Log (json);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement