如何通过统一的wwwform传递json我是unity新手。我想发送带有以下json数据的邮件请求**url**="http://index.php"**samplejson**={"id":"100","name":"abc"我正在使用C#任何人都可以为我提供解决方案吗?好吧,我正在使用这样的东西:publicclassRequestConnectionManager:Manager{publicintmaxSubmissionAttempts=3;publicCoroutinepost(){WWWFormplayForm=newWWWForm();playForm.AddField("id",myJson.id);playForm.AddField("名称",myJson.name);PostplayPost=newPost("http://index.php",playForm,maxSubmissionAttempts,this);返回StartCoroutine(PostWorker(playPost));}privateIEnumeratorPostWorker(PostplayPost){yieldreturnnull;yieldreturnplayPost.Submit();Debug.Log(playPost.Response);if(playPost.Error!=null){MessageBoxManager.Instance.Show("错误:"+playPost.Error,"错误",MessageBoxManager.OKCancelOptionLabels,MessageOptions.Ok);}else{try{//在这里做任何你想做的事情//Hashtableresponse=JsonReader.Deserialize(playPost.Response);//Debug.Log("UNITYLOG.."+response);}抓住(JsonDeserializationExceptionjsExc){Debug.Log(jsExc.Message);Debug.Log(playPost.Response);}catch(Exceptionexc){Debug.Log(exc.Message);Debug.Log(playPost.Response);}}}}//至于Manager类...usingUnityEngine;使用系统集合;//我想知道TManager:Singleton会产生什么约束...publicclassManager:SingletonWwhereTManager:MonoBehaviour{DontDestroyOnLoad(这个);DontDestroyOnLoad(游戏对象);}}希望这可以帮助!=)我做了以下操作走吧:==>以上就是C#学习教程:如何将json共享的所有内容通过一个统一的wwwform传递出去。如果对大家有用,需要详细了解C#学习教程,希望大家多多关注——使用UnityEngine;使用UnityEngine.UI;使用系统集合;使用System.Collections.Generic;publicclassbtnGetData:MonoBehaviour{voidStart(){gameObject.GetComponent().onClick.AddListener(TaskOnClick);}IEnumeratorWaitForWWW(WWWwww){yieldreturnwww;字符串txt="";如果(string.IsNullOrEmpty(www.error))txt=www.text;//成功文本elsetxt=www.error;//错误GameObject.Find("Txtdemo").GetComponent().text="++++++nn"+txt;}voidTaskOnClick(){try{GameObject.Find("Txtdemo").GetComponent().text="starting..";stringourPostData="{"plan":"TESTA02"";词典标题=新词典();headers.Add("Content-Type","application/json");//byte[]b=System.Text.Encoding.UTF8。获取字节();byte[]pData=System.Text.Encoding.ASCII.GetBytes(ourPostData.ToCharArray());///IIS主机发布...WWWapi=newWWW("http://192.168.1.120/si_aoi/api/total",pData,headers);///通过IIS托管获取...///WWWapi=newWWW("http://192.168.1.120/si_aoi/api/total?dynamix={"plan":"TESTA02"");StartCoroutine(WaitForWWW(api));}catch(UnityExceptionex){Debug.Log(ex.Message);}}}本文收集自网络,不代表立场,如侵权请点右联系管理员删除,如需转载请注明出处:
