[英]Asp.Net MVC Sending JSON As a String Always Truncated on Server
我正在将json数据作为字符串发送到asp.net mvc中的服务器,如下所示;
var dto = JSON.stringify(transObj);
console.log(String(dto));
$.ajax({
url: "/home/activity",
dataType: 'html',
data: "obj=" + String(dto) + "&trackedFromEntityTypeId=" + trackedFromEntityTypeId + "&trackedFromEntityType=" + trackedFromEntityType,
type: 'POST',
success: function (data) {
var jsonResult = JSON.parse(data);
if (jsonResult.status) {
bootbox.alert(jsonResult.message, function () {
window.location.href = "/";
});
} else {
displayError('Something bad happend. ' + data.message);
}
},
error: function (error) {
displayError('Something bad happend. ' + error.statusText);
},
complete: function () {
$.unblockUI();
}
});
如您所见,在将其发送到服务器之前,我将字符串写入控制台。 当我打开控制台窗口时,数据按预期的json格式显示,但是在服务器上,字符串被截断,如下图所示; 但是,控制台窗口中的原始json数据显示如下(如预期)。 我还使用jsonformatter将数据格式化为json并正确格式化了数据;
{ "ActivityInformation" : { "Attributes" : [ { "AttributeId" : "18",
"AttributeMappingId" : "17",
"AttributeName" : "Number of Helpers",
"AttributeValues" : [ { "Value" : "" } ]
},
{ "AttributeId" : "19",
"AttributeMappingId" : "12",
"AttributeName" : "Thickness",
"AttributeValues" : [ { "Value" : "" } ]
},
{ "AttributeId" : "14",
"AttributeMappingId" : "16",
"AttributeName" : "Width of Trench",
"AttributeValues" : [ { "Value" : "" } ]
},
{ "AttributeId" : "8",
"AttributeMappingId" : "13",
"AttributeName" : "Extra No",
"AttributeValues" : [ { } ]
},
{ "AttributeId" : "10",
"AttributeMappingId" : "15",
"AttributeName" : "Dozer PL.Num",
"AttributeValues" : [ ]
},
{ "AttributeId" : "7",
"AttributeMappingId" : "14",
"AttributeName" : "Shovel Plate No (Company)",
"AttributeValues" : [ { "Value" : "51741" } ]
}
],
"Id" : "25",
"Name" : "Formation Preperation",
"Tools" : [ { "ToolGroupName" : "Grader - MG 118 - 2003 - CAT 14H",
"Tools" : [ { "ToolAttributes" : [ { "AttributeId" : "19",
"AttributeMappingId" : "21",
"AttributeName" : "Thickness",
"AttributeValues" : [ { "Value" : "" } ]
},
{ "AttributeId" : "17",
"AttributeMappingId" : "22",
"AttributeName" : "Number of Masons",
"AttributeValues" : [ { "Value" : "" } ]
},
{ "AttributeId" : "7",
"AttributeMappingId" : "23",
"AttributeName" : "Shovel Plate No (Company)",
"AttributeValues" : [ { "Value" : "51741" } ]
}
] } ]
},
{ "ToolGroupName" : "Grader - MG 119 - 2007 - CAT 14H",
"Tools" : [ { "ToolAttributes" : [ ] } ]
},
{ "ToolGroupName" : "Backhoe Loader - BL 108 - 2007 - CAT 422E",
"Tools" : [ { "ToolAttributes" : [ { "AttributeId" : "18",
"AttributeMappingId" : "19",
"AttributeName" : "Number of Helpers",
"AttributeValues" : [ { "Value" : "" } ]
},
{ "AttributeId" : "13",
"AttributeMappingId" : "20",
"AttributeName" : "Width of Work",
"AttributeValues" : [ { "Value" : "" } ]
}
] } ]
},
{ "ToolGroupName" : "Backhoe Loader - BL 109 - 2007 - CAT 422E",
"Tools" : [ { "ToolAttributes" : [ ] } ]
},
{ "ToolGroupName" : "Backhoe Loader - BL 110 - 2007 - CAT 422E",
"Tools" : [ { "ToolAttributes" : [ ] } ]
},
{ "ToolGroupName" : "Backhoe Loader - BL112 - 2006 - CAT0416",
"Tools" : [ { "ToolAttributes" : [ ] } ]
}
]
},
"ActivityListInformation" : { "Id" : "14",
"Name" : "Road Activities"
},
"MilestoneInformation" : { "Id" : "8",
"Name" : "Milestone 3"
},
"PlaceInformation" : { "AreaId" : 4,
"AreaName" : "Area 1",
"RoadId" : 6,
"RoadName" : "108D",
"ZoneId" : 5,
"ZoneName" : "Zone 1"
},
"ProjectInformation" : { "Id" : "3",
"Name" : "LEVELLING AND ROADS IN AL BARSHA SOUTH – COMMUNITY 671 & 672"
},
"SubActivityInformation" : [ { "Attributes" : [ { "AttributeId" : "12",
"AttributeMappingId" : "6",
"AttributeName" : "End Chainage",
"AttributeValues" : [ { "Value" : "" } ]
},
{ "AttributeId" : "18",
"AttributeMappingId" : "7",
"AttributeName" : "Number of Helpers",
"AttributeValues" : [ { "Value" : "" } ]
}
],
"Id" : "1",
"Name" : "Test Sub Activity",
"Tools" : [ { "ToolGroupName" : "Grader - MG 118 - 2003 - CAT 14H",
"Tools" : [ { "ToolAttributes" : [ { "AttributeId" : "19",
"AttributeMappingId" : "21",
"AttributeName" : "Thickness",
"AttributeValues" : [ { "Value" : "" } ]
},
{ "AttributeId" : "17",
"AttributeMappingId" : "22",
"AttributeName" : "Number of Masons",
"AttributeValues" : [ { "Value" : "" } ]
},
{ "AttributeId" : "7",
"AttributeMappingId" : "23",
"AttributeName" : "Shovel Plate No (Company)",
"AttributeValues" : [ { "Value" : "51741" } ]
}
] } ]
},
{ "ToolGroupName" : "Backhoe Loader - BL 108 - 2007 - CAT 422E",
"Tools" : [ { "ToolAttributes" : [ { "AttributeId" : "18",
"AttributeMappingId" : "19",
"AttributeName" : "Number of Helpers",
"AttributeValues" : [ { "Value" : "" } ]
},
{ "AttributeId" : "13",
"AttributeMappingId" : "20",
"AttributeName" : "Width of Work",
"AttributeValues" : [ { "Value" : "" } ]
}
] } ]
}
]
},
{ "Attributes" : [ ],
"Id" : "2",
"Name" : "sdfdsfsdfsdf",
"Tools" : [ { "ToolGroupName" : "Backhoe Loader - BL 108 - 2007 - CAT 422E",
"Tools" : [ { "ToolAttributes" : [ { "AttributeId" : "18",
"AttributeMappingId" : "19",
"AttributeName" : "Number of Helpers",
"AttributeValues" : [ { "Value" : "" } ]
},
{ "AttributeId" : "13",
"AttributeMappingId" : "20",
"AttributeName" : "Width of Work",
"AttributeValues" : [ { "Value" : "" } ]
}
] } ]
},
{ "ToolGroupName" : "Backhoe Loader - BL 109 - 2007 - CAT 422E",
"Tools" : [ { "ToolAttributes" : [ ] } ]
}
]
}
]
}
只是在@Alexei Levenkov
评论的帮助下@Alexei Levenkov
。 问题是,我正在手动准备数据,并使用查询字符串格式将数据发送到服务器。 但是,我选择的方法是POST。 因此,我只是准备一个javascript对象,然后将其作为对象发送到服务器;
var dto = { "obj": JSON.stringify(transObj), "trackedFromEntityTypeId": trackedFromEntityTypeId, "trackedFromEntityType": trackedFromEntityType };
$.ajax({
url: "/home/activity",
dataType: 'html',
data: dto,
type: 'POST',
success: function (data) {
var jsonResult = JSON.parse(data);
if (jsonResult.status) {
bootbox.alert(jsonResult.message, function () {
window.location.href = "/";
});
} else {
displayError('Something bad happend. ' + data.message);
}
},
error: function (error) {
displayError('Something bad happend. ' + error.statusText);
},
complete: function () {
$.unblockUI();
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.