Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

397
Vistas
JSON truncated when passed from web page to ASP.NET Web API service

I have an ASP.NET Web API service that accepts JSON data. It works perfectly for all of our JSON data types except for one. Users are able to send inspection results from their mobile devices. The inspection results are received by an ASP.NET Web API service as JSON.

I have unit tests written in C# that are able to send inspection JSON data without a problem. But whenever I send the data from a web page the JSON data that is sent seems to be getting truncated.

This is what is sent.

{"Formname":"inspection","Formdata":{"UserId":1011357,"InspectionId":40013,"VehicleReg":"AA123ABC","Results":[{"QuestionId":100053,"OptionId":30192,"OptionResponse":"fantastic"}]},"Profile":{"EmailAddress":"myname@mycompany.com","OscarId":"1011369"}};

This is what is received.

{"Formname":"inspection","Formdata":{"UserId":1011357,"InspectionId":40013,"VehicleReg":"AA123ABC","Results":[{"QuestionId":100053,"OptionId":30192,"OptionResponse":"fantastic"

It's getting truncated at a length of 254.

Here is the AJAX that creates the request.

var url = "http://mywebservice/api/routingtasks?formname=inspection";

        $.ajax({
            type: "POST",
            url: url,
            contentType: "application/json",
            headers: { "Authorization" : "TESTUSER " + signedToken},
            data: JSON.stringify(formdata),
            success: function(data){
                alert("Task successfully processed.");
            },
            error: function(error){
                alert("error: " + JSON.stringify(error));
            }
        })

The signature of the Web API controller that receives the JSON data is this.

public HttpResponseMessage RoutePostData(string formname, [FromBody] JToken postdata)

My C# unit tests are able to send the same JSON data without a problem, but sending the JSON data from a web page is causing a problem.

over 4 years ago · Santiago Trujillo
3 Respuestas
Responde la pregunta

0

Your json is wrong. "Profile":{"EmailAddress" curly brace is missing. Not sure if it is copy paste error or your code error. However it truncates right after fantastic.

Change your json to

{"Formname":"inspection","Formdata":{"UserId":1011357,"InspectionId":40013,"VehicleReg":"AA123ABC","Results":[{"QuestionId":100053,"OptionId":30192,"OptionResponse":"fantastic"}]},"Profile":{"EmailAddress":"myname@mycompany.com","OscarId":"1011369"}}
over 4 years ago · Santiago Trujillo Denunciar

0

If formdata is already javascript object, you don't need to stringify it.

$.ajax({
            type: "POST",
            url: url,
            contentType: "application/json",
            headers: { "Authorization" : "TESTUSER " + signedToken},
            data: formdata,
            success: function(data){
                alert("Task successfully processed.");
            },
            error: function(error){
                alert("error: " + JSON.stringify(error));
            }
        })

You can read more on documentation page: http://api.jquery.com/jQuery.ajax/

over 4 years ago · Santiago Trujillo Denunciar

0

Try this:

<configuration>
     <appSettings>
          <add key="aspnet:MaxJsonDeserializerMembers" value="5000" />
     </appSettings>
</configuration>

Set the value to something of your choice.

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda