How to Pass a Json as Post Data to WWWForm

Hi, I have been searching for a solution for this,but unable to find a perfect solutions for this.
Please let me know how to pass a JSON String as Post Data to the WWWForm ?


You have to create a Dictionary and call an other constructor of WWW class.
To get your json (i use miniJson library, you can find many json parser for C# on internet) value :

		var dict = Json.Deserialize(get_data) as IDictionary;

	Dictionary<string,string> postParam = new Dictionary<string, string>();
	postParam.Add ("param", "value");

Example :

		WWWForm form = new WWWForm();
		foreach(KeyValuePair<String,String> post_arg in post)
			form.AddField(post_arg.Key, post_arg.Value);
		WWW www = new WWW(url, form);

I’ve done for doing this below. Let’s go : ==>

using UnityEngine;

using UnityEngine.UI;

using System.Collections;

using System.Collections.Generic;

public class btnGetData : MonoBehaviour

void Start()
IEnumerator WaitForWWW(WWW www)
    yield return www;
    string txt = "";

    if (string.IsNullOrEmpty(www.error))
        txt = www.text;  //text of success
        txt = www.error;  //error

    GameObject.Find("Txtdemo").GetComponent<Text>().text =  "++++++

" + txt;

void TaskOnClick()
        GameObject.Find("Txtdemo").GetComponent<Text>().text = "starting..";   

        string ourPostData = "{\"plan\":\"TESTA02\"";

        Dictionary<string,string> headers = new Dictionary<string, string>();
        headers.Add("Content-Type", "application/json");

        //byte[] b = System.Text.Encoding.UTF8.GetBytes();
        byte[] pData = System.Text.Encoding.ASCII.GetBytes(ourPostData.ToCharArray());

        ///POST by IIS hosting...
        WWW api = new WWW("", pData, headers);

        ///GET by IIS hosting...
        ///WWW api = new WWW("{\"plan\":\"TESTA02\"");


    catch (UnityException ex) { Debug.Log(ex.Message); }