Need Help in Networking i.e WWW

Hi
I’m trying to send the json data to server and my line of code is :

JSONObject j  =  new JSONObject(JSONObject.Type.OBJECT);
		for(int i=0;i<Contacts.ContactsList.Count;i++)
		{
			if(Contacts.ContactsList*.Phones.Count>0)*
  •  	{*
    
  •  		JSONObject contactList = new JSONObject(JSONObject.Type.ARRAY);*
    
  •  		JSONObject phoneNumber = new JSONObject(JSONObject.Type.ARRAY);*
    
  •  		j.AddField("Contacts",contactList);*
    

contactList.AddField(“Name”,Contacts.ContactsList_.FirstName+“”+Contacts.ContactsList*.LastName);
contactList.AddField(“PhoneNumber”,phoneNumber);
for(int k=0;k< Contacts.ContactsList[k].Phones.Count;k++)
{
phoneNumber.Add(Contacts.ContactsList.Phones[k]);
}*_

* string jsonData = j.Print();*
* Dictionary<string, string> header = new Dictionary<string,string>();*
* header.Add(“Content-Type”,“application/json”);*
* byte[] body = System.Text.Encoding.UTF8.GetBytes(jsonData);*

* WWW www = new WWW(URL,body,header);*
* StartCoroutine(PostDataEnumerator(www)); *

* }*
* }*
The problem is I don’t know what it do .
Can anyone help me with it to know what does it do and in which form of data the server recieve.
thanks

1 Answer

1

WWW www = new WWW(URL,body,header);
This will submit your Json data in bytes to the URL given. If you don’t know about this, you can use WWWForm instead. That might be much more straight forward to you. Unity - Scripting API: WWWForm

What it returns is the data get from your server. And the return type depends on your operation. For example, www.text returns the string form of the data and www.bytes returns the byte form of your result. And WWW www = new WWW(URL,body,header); should be stated inside coroutine body if you want it to provide concurrency.