My problem is that I have a webservice on ASP.net, which returns a JSON string object (no XML). But when I call the webmethod I have this:
<string xmlns="https://www.puzzlebooks.com.ar">
{"Tipo":null,"Anio":0,"Mes":null,"CuentaContable":null,"Total":0,"OId":0}
</string>
On client side, the message error is this: Unexpected token < in json at position 0
I expected this JSON:
{"Tipo":null,"Anio":0,"Mes":null,"CuentaContable":null,"Total": 0,"OId": 0}
a pure JSON
This is my web service code:
[WebMethod(EnableSession = true)]
[System.Web.Script.Services.ScriptMethod(ResponseFormat = System.Web.Script.Services.ResponseFormat.Json) ]
public string AcumuladoTotalCompraVenta_MesActual()
{
try
{
ModeloDeClases.Dominio.EstadisticaCompraVenta totalAcumulado = null;
totalAcumulado = RepositorioServicios.RepositoryServices.getInstance().getEstadisticasServices().CompraVenta_TotalAcumuladoDelMesActual(23);
if (totalAcumulado == null)
totalAcumulado = new ModeloDeClases.Dominio.EstadisticaCompraVenta();
string queHAY = new JavaScriptSerializer().Serialize(totalAcumulado);
// return totalAcumulado;
return queHAY;
}
catch (Exception ex)
{
this.Error(ex.Message);
return null;
}
}
And the code from client side (aspx page), is this:
<script type="text/javascript">
$(function ()
{
$.ajax
({
type: "POST",
dataType: "json",
contentType: "application/json",
url: "../webServices/wsEstadisticas.asmx/AcumuladoTotalCompraVenta_MesActual",
data: "{}",
success: chartAcumuladoComprasVentas_MesActual,
error: function (request, status, error)
{
alert('NOP!');
alert(request.statusText);
alert(error);
alert(request.toString());
}
});
})
function chartAcumuladoComprasVentas_MesActual()
{
alert('IT S WORK!');
}
</script>
I search on this site about the same problems, but doesn't work. The library Newtonsoft for JSON don't work for me, because I get the same result when I didn't use it.