Im trying to return detailed feedback in my API so created a class:
public class Notify
{
public class Root
{
Public string Error {get; set;}
Public Details Details {get; set;}
}
public class Details
{
public string FeedbackText {get; set;}
....
}
}
In my class i populate the object with
public JObject NotifyUser()
{
var r = new Notify.Root
{
Error = "Some error",
Details = new Notify.Details
{
FeedbackText = "Something to do"
}
};
return JObject.Parse(DoSomethingWithJson(r));
}
DoSomethingWithJson
is a string
method and passing in the object to modify the data.
In my API i have
var currentValue = NotifyUser(); // I see the Json and values in this variable but next line doesnt display the values only the Json fields
return StatusCode(HttpStatusCode.BadRequest, currentValue);
but it just returns the JSON fields without any data against any field. I convert it to a string and everything appears including the text assigned to each field but the response is listed as text and not JSON.
Ive tried converting the code to JsonConvert.SerialiseObject
but if its in a string format it shows the data otherwise its empty properties (i would like the response to be encoded as json).
Im not sure why its doing this? What have i missed? I did search around but most were targeting old versions so i feel im doing something wrong here.