AJAX JSON格式无效

时间:2017-01-06 14:30:01

标签: javascript jquery json ajax vb.net

我正在尝试通过AJAX将JSON数组传递到vb.net Web函数中,但是我收到了错误。

var retDets = {};


for (var i = 0, len = inputs.length; i < len; i++) {
    if (inputs[i].type === "hidden") {
        if (inputs[i].value !== "") {
            value.push(inputs[i].value)
            name.push(inputs[i].name)
            retDets[inputs[i].name] = inputs[i].value;
        }

//console.log(JSON.stringify(retDets))

args = '{"retDets":"' + JSON.stringify(retDets) + '"}';
aj('payment2', returnFunc, args, failedCallBack);

它假设要调用的web函数是这个(仅用于测试目的)

<WebMethod()>
Public Function payment2(retDets() As String) As String
    Dim a As String() = retDets
    Dim b As String
    Return b
End Function

我收到以下错误:

{"readyState":4,"responseText":"{\"Message\":\"Invalid object passed in, \\u0027:\\u0027 or \\u0027}\\u0027 expected. (15): {\\\"retDets\\\":\\\"{\\\"__VIEWSTATE\\\":\\\"/wEPDwULLTE0MDkxNzYwNDNkZIvZ4V6cac737n6rhojsjcpPY/VJaIhxf+LCGOM/JDUz\\\",\\\"PSPID\\\":\\\"cum1rp\\\",\\\"ORDERID\\\":\\\"1508ORD\\\",\\\"AMOUNT\\\":\\\"25000\\\",\\\"CURRENCY\\\":\\\"GBP\\\",\\\"LANGUAGE\\\":\\\"en_UK\\\",\\\"CN\\\":\\\"Nick\\\",\\\"EMAIL\\\":\\\"nickw@wdm.co.uk\\\",\\\"SHASIGN\\\":\\\"d22df14635f84283f9ba58ded25aa1716773893d\\\",\\\"TITLE\\\":\\\"WDM Payment Gateway\\\",\\\"BGCOLOR\\\":\\\"#4e84c4\\\",\\\"TXTCOLOR\\\":\\\"#FFFFFF\\\",\\\"TBLBGCOLOR\\\":\\\"#FFFFFF\\\",\\\"TBLTXTCOLOR\\\":\\\"#000000\\\",\\\"BUTTONBGCOLOR\\\":\\\"#00467F\\\",\\\"BUTTONTXTCOLOR\\\":\\\"#FFFFFF\\\",\\\"LOGO\\\":\\\"fill here your logo file name\\\",\\\"__VIEWSTATEGENERATOR\\\":\\\"B6E7D48B\\\"}\\\"}\",\"StackTrace\":\" at System.Web.Script.Serialization.JavaScriptObjectDeserializer.DeserializeDictionary(Int32 depth)\\r\\n at System.Web.Scr

1 个答案:

答案 0 :(得分:1)

执行此操作时:

args = '{"retDets":"' + JSON.stringify(retDets) + '"}';

输出将具有嵌套引号。

{"retDets":"{"asdasd":"asdasdas","ASdasdsad":"khkjhkjhjkh"}"}';

删掉引号

args = '{"retDets":' + JSON.stringify(retDets) + '}';