Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

394
Views
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.

about 4 years ago · Santiago Trujillo
3 answers
Answer question

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"}}
about 4 years ago · Santiago Trujillo Report

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/

about 4 years ago · Santiago Trujillo Report

0

Try this:

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

Set the value to something of your choice.

about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!