Json error on return from web request Post:

Apart from your issue that your request is malformed in some way, you again have the wrong handling of your error condition as I mentioned in your other question . While this will most likely not solve your issue (as you may not get an actual HTTP error back), you should still fix this.

As for building the json for the request or parsing the result you could simply use my SimpleJSON framework. This should avoid any json formatting issues. With it you could simply do

var json = new JSONObject();
json["input"]["urn"] = string;
var formats = json["output"]["formats"][0].AsObject;
formats["type"] = "arkit";
formats["scene"] = string;
string JsonData_ = json.ToString();

Note that your “string” variable could contain characters that need to be escaped. My framework takes care of that. Some of the characters that need to be escaped are “\n”, “\r”, “\”.

It can also be used to parse the result (given that the request was successful and you actually got json back)

var node = JSONNode.Parse(postJob.downloadHandler.text);
string result = node["result"]; // should contain "created"
string type = node["acceptedJobs"]["output"]["formats"][0]["type"]; // should contain "arkit"

With this framework you don’t have to create seperate classes for the various requests or responses. It supports any valid json, even those which can not be mapped to C# objects (like objects keys that start with a number or contain spaces).

1 Like