I'm developing an ASPNetCore WebApi. In the get method I'm using Newtonsoft.Json and deserialize an generic object ( I'm not using a class model ) I get the response, works fine, but this have back slashes (in postman and in swagger)
[HttpGet]
[Route( "Obtener/{dwdocid:int}" )]
public IActionResult Obtener ( int dwdocid ) {
var dictionary = ( IDictionary<string, object> ) flexible; // for build the data
string json=null;
try {
for ( int i = 1; i < item.Fields.Count - 1; i++ ) {
// Taking data form another platform ( other system )*******
// this platoform give us the data as strings
// I make a diference between field and value for creating json response
var field = item.Fields[i].FieldName.ToString();
var value = item.Fields[i].Item == null ? "" : item.Fields[i].Item.ToString();
dictionary.Add( field, value ); // building json
}
} catch ( Exception error ) {
return StatusCode( StatusCodes.Status500InternalServerError, new { mensaje = error.Message, response = JsonConvert.SerializeObject( dictionary ) } );
}
dk.desconectar( UriPlatform, dwUser, dwPass ); // diconnection
return StatusCode( StatusCodes.Status200OK, new { mensaje = "OK ;)", lista = JsonConvert.SerializeObject( dictionary ) } );
// return Json SerializeObject
}
I've converted te response in string for remove back slashes, but is not working.
How can I get a normal json response?? Please, I hope anyone can help me.
thanks.