edited December 2021 in ORK Scripting
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.

difficultBody = {
"submissions": [
"language_id": 46,
"source_code": "echo hello from Bash"
"language_id": 71,
"source_code": "print(\"hello from Python\")"
"language_id": 72,
"source_code": "puts(\"hello from Ruby\")"

So, lets say that the body was instead something like this:

simpleBody = {
"name":"Jack Ma",

I would send it like this :

WWWForm submissionForm = new WWWForm();
submissionForm.AddField("name","Jack Ma");

//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
Post edited by Blitzkreig95 on
  • 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

    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);

Sign In or Register to comment.