2 ss27588709 ss27588709 于 2014.12.17 10:01 提问

AJAX POST 字符串(长度400左右的JSON格式字符串)出现字符串在后台接收时混乱

前端 是HTML,通过AJAX异步调用,
其中masterString是将JSON格式的数组转换成string,(使用json2.js与自己写的jsonToString)均有问题。
$.ajax({
url: "../Services/Service" + handletype + ".ashx",
type: "post",
dataType: "text",
data: "add=fl&result=" + masterString + "&encoded=" + encodeURIComponent(masterString),
async: true,
success: function (data) {}
});
后台是.NET写的ashx的generic handler,后台捕获数据时发现:
约5000次请求中会有1-2次数据异常,
key:add
value:fl
key:result
value:{"MasterID":"7","UserOpenID":"","QAList":[{"Q":"733","A":"2072"},{"Q":"734","A":"2076"},{"Q":"735","A":"2079"},{"Q":"736","A":"2082"},{"Q":"737","A":"2085"},{"Q":"738","A":"2088"},{"Q":"739","A":"2091"},{"Q":"740","A":"2094"},{"Q":"741","A":"2097"},{"Q":"742","A":"2099"},{"Q":"743","A":"2103"},{"Q":"744","{"Q":"747","A":"2114"},{"Q":"748","A":"2119"},{"Q":"749","A":"2122"},{"Q":"750","A":"2123"},{"Q":"751","A":"2128"},{"Q":"752","A":"2129"},{"Q":"753","A":"2134"},{"Q":"754","A":"2137"},{"Q":"755","A":"2138"},{"Q":"756","A":"2142"},{"Q":"757","A":"2144"},{"Q":"758","A":"2148"},{"Q":"759","A":"2150"},{"Q":"760","A":"2151"},{"Q":"761","A":"2154"},{"Q":"762","A":"2158"},{"Q":"763","A":"2163"},{"Q":"764","A":"2168"},{"Q":"765","A":"2173"}]}
key:encoded
value:{"MasterID":"7","UserOpenID":"","QAList":[{"Q":"733","A":"2072"},{"Q":"734","A":"2076"},{"Q":"735","A":"2079"},{"Q":"736","A":"2082"},{"Q":"737","A":"2085"},{"Q":"738","A":"2088"},{"Q":"739","A":"2091"},{"Q":"740","A":"2094"},{"Q":"741","A":"2097"},{"Q":"742","A":"2099"},{"Q":"743","A":"2103"},{"Q":"744","A":"2106"},{"Q":"745","A":"2109"},{"Q":"746","A":"2112"},{"Q":"747","A":"2114"},{"Q":"748","A":"2119"},{"Q":"749","A":"2122"},{"Q":"750","A":"2123"},{"Q":"751","A":"2128"},{"Q":"752","A":"2129"},{"Q":"753","A":"2134"},{"Q":"754","A":"2137"},{"Q":"755","A":"2138"},{"Q":"756","A":"2142"},{"Q":"757","A":"2144"},{"Q":"758","A":"2148"},{"Q":"759","A":"2150"},{"Q":"760","A":"2151"},{"Q":"761","A":"2154"},{"Q":"762","A":"2158"},{"Q":"763","A":"2163"},{"Q":"764","A":":"2163"},{"Q":"764","A":"2168"},{"Q":"765","A":"2173"}]}

发现:
不进行encode在Q744处出现异常(异常位置随机,每次都不一样。){"Q":"744","{"Q":"747","A":"2114"},encode部分在764处异常,"Q": "764","A": ":"2163"},

求各位大神帮忙支招。

5个回答

ss27588709
ss27588709   2014.12.19 10:53
已采纳

有时候数据还是这样的

FORM DATA:
key:
value:FF�f�b'V7W�Gӷ"�7GV'�D"�"c"�"U7V'�V�D"�""�"Ė7G"���""�"cc�"�""�"�S#"�·""�"cs"�""�"�Sc"�·""�"cs"�""�"�c"�·""�"cs#"�""�"�c3"�·""�"cs3"�""�"�c�"�·""�"csC"�""�"�sC"�·""�"csS"�""�"�sS"�·""�"csc"�""�"�ss"�·""�"css"�""�"��"�·""�"cs�"�""�"��C"�·""�"cs�"�""�"���"�·""�"c�"�""�"��#"�·""�"c�"�""�"��s"�·""�"c�#"�""�"�"�·""�"c�3"�""�"�S"�·""�"c�C"�""�"��"�·""�"c�S"�""�"�#"�·""�"c�c"�""�"�S"�·""�"c�s"�""�"��"�·""�"c��"�""�"�#S"�·""�"c��"�""�"�#s"�·""�"c�"�""�"�3#"�·""�"c�"�""�"�3c"�·""�"c�#"�""�"�3�"�·""�"c�3"�""�"�Cc"�·""�"c�C"�""�"�Cs"�·""�"c�S"�""�"�S"�·""�"c�c"�""�"�SS"�·""�"c�s"�""�"�S�"�·""�"c��"�""�"�cS"���bV�6�FVF�Rs$R##�7GV'�DR##R3R##cR##R#4R##U7V'�V�DR##R3R##R##R#4R##Ė7GR##R3RS$Rs$R##R##R3R##cc�R##R#4R##R##R3R##�S#R##RsDR#4Rs$R##R##R3R##csR##R#4R##R##R3R##�ScR##RsDR#4Rs$R##R##R3R##csR##R#4R##R##R3R##�cR##RsDR#4Rs$R##R##R3R##cs#R##R#4R##R##R3R##863"},{"Q":"673","A":"1868"},{"Q":"674","A":"1874"},{"Q":"675","A":"1875"},{"Q":"676","A":"1877"},{"Q":"677","A":"1881"},{"Q":"678","A":"1884"},{"Q":"679","A":"1888"},{"Q":"680","A":"1892"},{"Q":"681","A":"1897"},{"Q":"682","A":"1901"},{"Q":"683","A":"1905"},{"Q":"684","A":"1908"},{"Q":"685","A":"1912"},{"Q":"686","A":"1915"},{"Q":"687","A":"1919"},{"Q":"688","A":"1925"},{"Q":"689","A":"1927"},{"Q":"690","A":"1932"},{"Q":"691","A":"1936"},{"Q":"692","A":"1939"},{"Q":"693","A":"1946"},{"Q":"694","A":"1947"},{"Q":"695","A":"1951"},{"Q":"696","A":"1955"},{"Q":"697","A":"1959"},{"Q":"698","A":"1965"}]}

值不能为 null。
参数名: input

save4me
save4me   Ds   Rxr 2014.12.17 10:47

使用
data: "add=fl&result=" + masterString + "&encoded=" + encodeURIComponent(JSON.stringify(masterString)),

save4me
save4me   Ds   Rxr 2014.12.18 09:17

上面的答案有帮助吗?如果还有问题,请提出来,如果对答案满意,请顶一下,并标记为采纳答案,谢谢!

ss27588709
ss27588709   2014.12.19 10:46

怎么可能,masterString本来就是是一个json的字符串而非json对象,固不可能能通过这样的方式解决。

qq_28589949
qq_28589949   2016.10.11 09:02

就是后台返回的数据过长引起的

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!