如何通过JSON与团结w​​wwform [英] how to pass json with wwwform in unity

查看:148
本文介绍了如何通过JSON与团结w​​wwform的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是一个团结的新手。

我想发送POST请求具有以下团结JSON数据

i want to send a post request having following json data in unity

**url** = "http://index.php"

**sampple json** = {"id":"100","name":"abc"}

我使用C#

谁能给我提供了一个解决方案?

can anyone provide me a solution for this?

推荐答案

嗯,我像这样的工作

    public class RequestConnectionManager : Manager<RequestConnectionManager>
    {

    public int maxSubmissionAttempts = 3;

    public Coroutine post() {
                WWWForm playForm = new WWWForm();
                playForm.AddField("id", myJson.id);
                playForm.AddField("name", myJson.name);

                Post playPost = new Post("http://index.php", playForm, maxSubmissionAttempts, this);
                return StartCoroutine(PostWorker(playPost));
            }

    private IEnumerator PostWorker(Post playPost)
        {
            yield return null;
            yield return playPost.Submit();

            Debug.Log(playPost.Response);
            if (playPost.Error != null)
            {
                MessageBoxManager.Instance.Show("Error: " + playPost.Error, "Error", MessageBoxManager.OKCancelOptionLabels, MessageOptions.Ok);
            }
            else
            {
                try
                {
                    //do whatever you want in here
                    //Hashtable response = JsonReader.Deserialize<Hashtable>(playPost.Response);
                    //Debug.Log("UNITY LOG..." + response);

                }
                catch (JsonDeserializationException jsExc)
                {
                    Debug.Log(jsExc.Message);
                    Debug.Log(playPost.Response);
                }
                catch (Exception exc)
                {
                    Debug.Log(exc.Message);
                    Debug.Log(playPost.Response);
                }

            }
        }

    }

//As for the Manager class...

using UnityEngine;
using System.Collections;


// I wonder what the constraint where TManager : Singleton<TManager> would produce...
public class Manager<TManager> : SingletonW<TManager> where TManager : MonoBehaviour
{

    override protected void Awake()
    {
        base.Awake();
        DontDestroyOnLoad(this);
        DontDestroyOnLoad(gameObject);
    }

}



希望这有助于! =)

Hope this helps! =)

这篇关于如何通过JSON与团结w​​wwform的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆