Sorry if this feels a bit of a tangent but I am using this functionality in my game and some other guys might also need networking in their game.
I have used WWWForm earlier and I used it to send string, int data using AddField. Now I wish to send an Array of javascript objects and I can't wrap my head around how I would do that.
WWWForm submissionForm = new WWWForm(); submissionForm.AddField("name","Jack Ma"); submissionForm.AddField("age",57); submissionForm.AddField("nationality","Chinese");
//Followed by- Attach the submissionForm to UnityWebRequest.Post()
But how do I do it for "difficultBody". WWWForm allows for int,string. But how would you add an array of javascript objects. I really don't understand the internals and that is probably my real problem. Like how does Unity convert the WWWForm to JSON and then stringify it before sending it off - this mechanism is not clear. Any help or direction would be welcome. Thanks
Hello @Blitzkreig95 I think you are missing having a class to parse your json text, then after parsing the json into that class you can easily assign the values to your WWWForm function e.g. [System.Serializable] public class SimpleBodyParseJsonData { public string Name = System.String.Empty; public string Age= System.String.Empty; public string Nationality= System.String.Empty; }
Then you can use SimpleBodyParseJsonData simpleBody = JsonUtility.FromJson<SimpleBodyParseJsonData >(your json as TextAsset) // or save the stringify json into an ORK Game Variable, or Combatant local Variable
WWWForm submissionForm = new WWWForm(); submissionForm.AddField("name", simpleBody.Name); submissionForm.AddField("age",simpleBody.Age); submissionForm.AddField("nationality",simpleBody.Nationality);
I think you are missing having a class to parse your json text, then after parsing the json into that class you can easily assign the values to your WWWForm function
e.g.
[System.Serializable]
public class SimpleBodyParseJsonData
{
public string Name = System.String.Empty;
public string Age= System.String.Empty;
public string Nationality= System.String.Empty;
}
Then you can use
SimpleBodyParseJsonData simpleBody = JsonUtility.FromJson<SimpleBodyParseJsonData >(your json as TextAsset)
// or save the stringify json into an ORK Game Variable, or Combatant local Variable
WWWForm submissionForm = new WWWForm();
submissionForm.AddField("name", simpleBody.Name);
submissionForm.AddField("age",simpleBody.Age);
submissionForm.AddField("nationality",simpleBody.Nationality);