Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

399
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda