I am trying to return a JSON result from a REST API that includes a JsonObject as an element.
var aJsonObject = new JObject();
aJsonObject.Add("somefield", "somevalue" );
aJsonObject.Add("someotherfield", 1995);
return Json( new { status = "success", result = aJsonObject } );
The client receives an empty nested arrays:
{"status":"success","result":[[[]],[[]]]}
My work around, which I don't love, is to serialize the JsonObject, thus sending it as a string and then having the client parse it. It works, but it's a bit ugly.
Is this a bug or am I doing it wrong?
NOTE: 8/3/18 I edited the variable declaration to correct a typo - it was jsonObject and should have been aJsonObject
jsonObjectbut populating and returningaJsonObject? Are you simply mixing up your variables?