国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

使用unity 5.3版本以上 自帶Json解析器與后臺進行登錄驗證。

2019-11-07 23:55:57
字體:
來源:轉載
供稿:網友

使用unity 5.3版本以上 自帶Json解析器與后臺進行登錄驗證。

using UnityEngine;using System.Collections;public class UserInfo{ //用戶信息 由賬號 密碼 驗證碼 組成 public string userAccount; public string userPassWord; public string secureCode; public string backInfo;//這個變量用來保存服務器返回的消息}public class GobleController : MonoBehaviour { //后端提供的POST請求地址 string postUrl="www.baidu.com...."; // Use this for initialization void Start () { } //點擊登錄按鈕的方法 public void LogInClick() { //將賬號密碼信息 填入表單 WWWForm userInfoForm = new WWWForm (); userInfoForm.AddField ("userAccount", "MaYun001"); userInfoForm.AddField ("userPassword", "8888888"); //啟用協同程序進行登錄 StartCoroutine (SendPost (postUrl,userInfoForm )); } // Update is called once per frame void Update () { } /// <summary> /// 這個發送POST請求的方法 /// 參數1:后臺給的URL接口 /// 參數2:發送的表單數據 /// </summary> /// <returns>The register.</returns> /// <param name="url">URL.</param> /// <param name="_form">Form.</param> public IEnumerator SendPost(string url,WWWForm _wform) { //將參數用一個WWW對象保存起來 WWW postData = new WWW (url, _wform); //向后臺發送數據,并等待后臺返回的數據。 yield return postData; //和后臺協商好,返回的消息也是在發回的消息是UserInfo類型 并將返回消息保存在backInfo上 //將后臺返回的數據JSON格式進行解析 解析成UuserInfo對象 UserInfo myUserInfo = JsonUtility.FromJson<UserInfo >(postData.text ); // 對返回結果進行判斷 if (postData.error != null) { Debug.Log ("返回的數據錯誤不為空!說明返回的消息有錯"); } else { //將返回消息的文本打印出來 Debug.Log (postData.text ); if (myUserInfo.backInfo == "登錄成功") { Debug.Log ("登錄成功"); } else if (myUserInfo.backInfo =="登錄失敗") { Debug.Log ("登錄失敗"); } } }}
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 淄博市| 香港| 克拉玛依市| 新沂市| 梅河口市| 西青区| 武穴市| 安徽省| 河东区| 永清县| 安庆市| 固原市| 清涧县| 柯坪县| 威远县| 邵阳市| 三明市| 黑水县| 连江县| 行唐县| 桦甸市| 阳朔县| 小金县| 阆中市| 北海市| 榕江县| 甘肃省| 大同县| 岳阳县| 长春市| 永宁县| 邓州市| 家居| 鲁甸县| 淅川县| 安多县| 安泽县| 卢湾区| 怀远县| 肃宁县| 贵定县|