-1

我正在尝试将 json 对象发送到 Web 服务。我在萤火虫中遇到错误。

{"Message":"Invalid object passed in, \u0027:\u0027 or \u0027}\u0027 expected. (3423): {\u0027GUID\u0027:\u0027urhhh1bqbezjvb45dnqlgj45\u0027,\u0027RuleName\u0027:\u0027Summary Check\u0027,\u0027LinkArray\u0027:\u0027[{\"from\":\"Start\",\"to\":\"Count\",\"text\":\"Next\",\"fromPort\":\"5\",\"toPort\":\"1\"},{\"from\":\"Count.6\",\"to\":\"Multiple Decisions\",\"text\":\"Next\",\"fromPort\":\"5\",\"toPort\":\"1\"},{\"from\":\"Multiple Decisions\",\"to\":\"Status\",\"text\":\"True\",\"fromPort\":\"3\",\"toPort\":\"7\"},{\"from\":\"Multiple Decisions\",\"to\":\"Finish\",\"text\":\"False\",\"fromPort\":\"5\",\"toPort\":\"1\"},{\"from\":\"Status\",\"to\":\"Finish.14\",\"text\":\"Next\",\"fromPort\":\"3\",\"toPort\":\"7\"},{\"from\":\"Count\",\"to\":\"Count.6\",\"text\":\"Next\",\"fromPort\":\"5\",\"toPort\":\"1\"}]\u0027,\u0027NArray\u0027:\u0027[{\"key\":\"StatusText\",\"category\":\"Comment\",\"location\":\"10 10\",\"text\":\"Step 10\\rEvent = PAEditQuote\\rModel = PAStatementValidation\",\"figure\":\"RoundedRectangle\"},{\"key\":\"Start\",\"category\":\"begin\",\"type\":\"Start\",\"location\":\"169 124\",\"size\":\"57 55\",\"text\":\"\",\"tooltip\":\"Datasource=\",\"break\":\"false\",\"Properties\":{\"Name\":\"Start\"}},{\"key\":\"Count.6\",\"category\":\"image\",\"type\":\"Count\",\"location\":\"172 378\",\"size\":\"49 49\",\"text\":\"# of Sele QA’s\",\"tooltip\":\"Number of Sele Question Answers=Statement Sele QA Where Statement Sele Answer Required equals Y\",\"break\":\"false\",\"Properties\":{\"Variable\":\"[:000013]\",\"Name\":\"Count\",\"Message\":\"Count\",\"ShortName\":\"Statement Sele QA\",\"Operand1\":\"equals\",\"Value1\":\"Y\",\"CountType1\":\"All\",\"DecShortName\":\"Statement Sele Answer Required\",\"DataBase\":\"DB1\",\"Table\":\"SHSeleQuestions\",\"XMLPath\":\"DB1\\\\SHSeleQuestions\",\"DecXMLPath\":\"DB1\\\\SHSeleQuestions\\\\ResponseReqInd\"}},{\"key\":\"Multiple Decisions\",\"category\":\"Decision\",\"type\":\"DecPlus\",\"location\":\"169 508\",\"size\":\"75 56\",\"text\":\"If no required answers given\",\"tooltip\":\"Number of Sele Question Answers is greater than 0\",\"break\":\"false\",\"Properties\":{\"DecisionInd\":\"True\",\"Variable1\":\"[:000013]\",\"Operand1_1\":\"is greater than\",\"Value1_1\":\"0\",\"Name\":\"DecPlus\",\"Variable2\":\"[:000015]\",\"Operand1_2\":\"equals\",\"Value1_2\":\"0\"}},{\"key\":\"Finish\",\"category\":\"end\",\"type\":\"Finish\",\"location\":\"172 625\",\"size\":\"57 55\",\"text\":\"\",\"tooltip\":\"\",\"break\":\"false\",\"Properties\":{\"Name\":\"Finish\"}},{\"key\":\"Status\",\"category\":\"image\",\"type\":\"Status\",\"location\":\"313 508\",\"size\":\"53 49\",\"text\":\"HOST003\",\"tooltip\":\"Warning=HOST003 - All Questions must be answered on the Statement Page.\",\"break\":\"false\",\"Properties\":{\"Name\":\"Status\",\"Message\":\"Validation.IValidation\",\"StatusCode\":\"PADriver002\",\"StatusType\":\"Error\",\"StatusMessage\":\"All Questions must be answered on the Statement Page.\",\"StatusPage\":\"PAStatement.aspx\",\"Unique\":\"False\"},\"Unique\":\"False\"},{\"key\":\"Finish.14\",\"category\":\"end\",\"type\":\"Finish\",\"location\":\"461 508\",\"size\":\"57 55\",\"text\":\"Stop Model\",\"tooltip\":\"\",\"break\":\"false\",\"Properties\":{\"Name\":\"Finish\",\"Termination\":\"StopModel\"}},{\"key\":\"Count\",\"category\":\"image\",\"type\":\"MultiCount\",\"location\":\"172 252\",\"size\":\"49 49\",\"selected\":\"true\",\"text\":\"Statement Answer\",\"tooltip\":\"=\",\"break\":\"false\",\"Properties\":{\"Variable\":\"[:000015]\",\"Name\":\"MultiCount\",\"Message\":\"MultiCount\",\"ShortName\":\"Statement Answer\",\"CountType1\":\"All\",\"ShortName1\":\"Statement Answer\",\"Operand1_1\":\"does not equal\",\"Item\":\"1\",\"XMLDoc\":\"PagePolicyData\",\"XMLPath\":\"PagePolicyData\\\\ValidationMessage\\\\PageContent\\\\ACORD\\\\PersAutoLineBusiness\\\\QuestionAnswer\\\\YesNoCd\",\"XMLPath1\":\"PagePolicyData\\\\ValidationMessage\\\\PageContent\\\\ACORD\\\\PersAutoLineBusiness\\\\QuestionAnswer\\\\YesNoCd\",\"XMLCondPath\":\"Root\\\\PagePolicyData\\\\ValidationMessage\\\\PageContent\\\\ACORD\\\\PersAutoLineBusiness\\\\QuestionAnswer{((YesNoCd != \u0027\u0027))}\\\\YesNoCd\"}},{\"category\":\"Comment\",\"location\":\"450 50\",\"size\":\"150 38\",\"figure\":\"RoundedRectangle\",\"text\":\"Summary Check\"}]\u0027,\u0027RulesArray\u0027:\u0027{\"0\":\"Check Bypass\",\"1\":\"Bypass Edorsement\",\"2\":\"Statement Questions\"}\u0027}","StackTrace":"   at System.Web.Script.Serialization.JavaScriptObjectDeserializer.DeserializeDictionary(Int32 depth)\r\n   at System.Web.Script.Serialization.JavaScriptObjectDeserializer.DeserializeInternal(Int32 depth)\r\n   at System.Web.Script.Serialization.JavaScriptObjectDeserializer.BasicDeserialize(String input, Int32 depthLimit, JavaScriptSerializer serializer)\r\n   at System.Web.Script.Serialization.JavaScriptSerializer.Deserialize(JavaScriptSerializer serializer, String input, Type type, Int32 depthLimit)\r\n   at System.Web.Script.Serialization.JavaScriptSerializer.Deserialize[T](String input)\r\n   at System.Web.Script.Services.RestHandler.GetRawParamsFromPostRequest(HttpContext context, JavaScriptSerializer serializer)\r\n   at System.Web.Script.Services.RestHandler.GetRawParams(WebServiceMethodData methodData, HttpContext context)\r\n   at System.Web.Script.Services.RestHandler.ExecuteWebServiceCall(HttpContext context, WebServiceMethodData methodData)","ExceptionType":"System.ArgumentException"}

Jquery ajax 对 web 服务的调用如下:

    var LinkArray = localStorage['LinkArray'];
    var NodeArray = localStorage['NArray'].replace("'", "\'");           
    var RulesArray=localStorage['TabList'];
    var Parameters = "{'GUID':'" + GetQueryStringValue('GUID') + "','RuleName':'" + $("#rulename").text() + "','LinkArray':'" + LinkArray + "','NArray':'" + NodeArray + "','RulesArray':'" + RulesArray + "'}";
    //var Parameters = '{"GUID":"' + GetQueryStringValue("GUID") + '","RuleName":"' + $('#rulename').text() + '","LinkArray":"' + LinkArray + '","NArray":"' + NodeArray + '","RulesArray":"' + RulesArray + '"}';

    $.ajax({
        type: "POST",
        url: "../RulesWebService.asmx/UpdateAllProperties",
        data: Parameters,            
        contentType: 'application/json; charset=utf-8',            
        crossBrowser: true,
        success: function (GetStatusRs) {

        },
        //onerror throw error.
        error: function (XMLHttpRequest, textStatus, errorThrown) {
            alert('Error Getting status for parameters: - Error:' + errorThrown);
        }
    });

我的网络方法具有以下结构:

<WebMethod(EnableSession:=True)> _
  Public Function UpdateAllProperties(ByVal GUID As String, ByVal RuleName As String, ByVal LinkArray As String, ByVal NArray As String, ByVal RulesArray As String) As String
  'some stuff here.
End Function

下面是我将其发布到服务器的参数值。

{'GUID':'urhhh1bqbezjvb45dnqlgj45','RuleName':'Summary Check','LinkArray':'[{"from":"Start","to":"Count","text":"Next","fromPort":"5","toPort":"1"},{"from":"Count.6","to":"Multiple Decisions","text":"Next","fromPort":"5","toPort":"1"},{"from":"Multiple Decisions","to":"Status","text":"True","fromPort":"3","toPort":"7"},{"from":"Multiple Decisions","to":"Finish","text":"False","fromPort":"5","toPort":"1"},{"from":"Status","to":"Finish.14","text":"Next","fromPort":"3","toPort":"7"},{"from":"Count","to":"Count.6","text":"Next","fromPort":"5","toPort":"1"}]','NArray':'[{"key":"StatusText","category":"Comment","location":"10 10","text":"Step 10\rEvent = PAEditQuote\rModel = PAStatementValidation","figure":"RoundedRectangle"},{"key":"Start","category":"begin","type":"Start","location":"169 124","size":"57 55","text":"","tooltip":"Datasource=","break":"false","Properties":{"Name":"Start"}},{"key":"Count.6","category":"image","type":"Count","location":"172 378","size":"49 49","text":"# of Sele QA’s","tooltip":"Number of Sele Question Answers=Statement Sele QA Where Statement Sele Answer Required equals Y","break":"false","Properties":{"Variable":"[:000013]","Name":"Count","Message":"Count","ShortName":"Statement Sele QA","Operand1":"equals","Value1":"Y","CountType1":"All","DecShortName":"Statement Sele Answer Required","DataBase":"DB1","Table":"SHSeleQuestions","XMLPath":"DB1\\SHSeleQuestions","DecXMLPath":"DB1\\SHSeleQuestions\\ResponseReqInd"}},{"key":"Multiple Decisions","category":"Decision","type":"DecPlus","location":"169 508","size":"75 56","text":"If no required answers given","tooltip":"Number of Sele Question Answers is greater than 0","break":"false","Properties":{"DecisionInd":"True","Variable1":"[:000013]","Operand1_1":"is greater than","Value1_1":"0","Name":"DecPlus","Variable2":"[:000015]","Operand1_2":"equals","Value1_2":"0"}},{"key":"Finish","category":"end","type":"Finish","location":"172 625","size":"57 55","text":"","tooltip":"","break":"false","Properties":{"Name":"Finish"}},{"key":"Status","category":"image","type":"Status","location":"313 508","size":"53 49","text":"HOST003","tooltip":"Warning=HOST003 - All Questions must be answered on the Statement Page.","break":"false","Properties":{"Name":"Status","Message":"Validation.IValidation","StatusCode":"PADriver002","StatusType":"Error","StatusMessage":"All Questions must be answered on the Statement Page.","StatusPage":"PAStatement.aspx","Unique":"False"},"Unique":"False"},{"key":"Finish.14","category":"end","type":"Finish","location":"461 508","size":"57 55","text":"Stop Model","tooltip":"","break":"false","Properties":{"Name":"Finish","Termination":"StopModel"}},{"key":"Count","category":"image","type":"MultiCount","location":"172 252","size":"49 49","selected":"true","text":"Statement Answer","tooltip":"=","break":"false","Properties":{"Variable":"[:000015]","Name":"MultiCount","Message":"MultiCount","ShortName":"Statement Answer","CountType1":"All","ShortName1":"Statement Answer","Operand1_1":"does not equal","Item":"1","XMLDoc":"PagePolicyData","XMLPath":"PagePolicyData\\ValidationMessage\\PageContent\\ACORD\\PersAutoLineBusiness\\QuestionAnswer\\YesNoCd","XMLPath1":"PagePolicyData\\ValidationMessage\\PageContent\\ACORD\\PersAutoLineBusiness\\QuestionAnswer\\YesNoCd","XMLCondPath":"Root\\PagePolicyData\\ValidationMessage\\PageContent\\ACORD\\PersAutoLineBusiness\\QuestionAnswer{((YesNoCd != ''))}\\YesNoCd"}},{"category":"Comment","location":"450 50","size":"150 38","figure":"RoundedRectangle","text":"Summary Check"}]','RulesArray':'{"0":"Check Bypass","1":"Bypass Edorsement","2":"Statement Questions"}'}
4

2 回答 2

2

您是否尝试过使用JSON.stringify()。同样使用 JSON.stringify,您可以使用一个对象来存储每个值,并使用 stringify 使其成为 JSON。

var LinkArray = localStorage['LinkArray'];
    var NodeArray = localStorage['NArray'].replace("'", "\'");           
    var RulesArray=localStorage['TabList'];
    var Parameters = "{'GUID':'" + GetQueryStringValue('GUID') + "','RuleName':'" + $("#rulename").text() + "','LinkArray':'" + LinkArray + "','NArray':'" + NodeArray + "','RulesArray':'" + RulesArray + "'}";
    //var Parameters = '{"GUID":"' + GetQueryStringValue("GUID") + '","RuleName":"' + $('#rulename').text() + '","LinkArray":"' + LinkArray + '","NArray":"' + NodeArray + '","RulesArray":"' + RulesArray + '"}';

$.ajax({
    type: "POST",
    url: "../RulesWebService.asmx/UpdateAllProperties",
    data: JSON.stringify(Parameters),            
    contentType: 'application/json; charset=utf-8',            
    crossBrowser: true,
    success: function (GetStatusRs) {

    },
    //onerror throw error.
    error: function (XMLHttpRequest, textStatus, errorThrown) {
        alert('Error Getting status for parameters: - Error:' + errorThrown);
    }
});

编辑 1:您的对象应如下所示:

var Parameters = {};
Parameters.Guid = 'your value';
// the rest of the fields from your object.
于 2013-03-20T06:38:16.193 回答
0

您发布服务器的参数值格式错误。使用http://jsonlint.com/更正您的 json。现在用this作为参数试试..

{
        "GUID": "urhhh1bqbezjvb45dnqlgj45",
        "RuleName": "SummaryCheck",
        "LinkArray": [
            {
                "from": "Start",
                "to": "Count",
                "text": "Next",
                "fromPort": "5",
                "toPort": "1"
            },
            {
                "from": "Count.6",
                "to": "Multiple Decisions",
                "text": "Next",
                "fromPort": "5",
                "toPort": "1"
            },
            {
                "from": "Multiple Decisions",
                "to": "Status",
                "text": "True",
                "fromPort": "3",
                "toPort": "7"
            },
            {
                "from": "Multiple Decisions",
                "to": "Finish",
                "text": "False",
                "fromPort": "5",
                "toPort": "1"
            },
            {
                "from": "Status",
                "to": "Finish.14",
                "text": "Next",
                "fromPort": "3",
                "toPort": "7"
            },
            {
                "from": "Count",
                "to": "Count.6",
                "text": "Next",
                "fromPort": "5",
                "toPort": "1"
            }
        ],
        "NArray": [
            {
                "key": "StatusText",
                "category": "Comment",
                "location": "10 10",
                "text": "Step 10\rEvent = PAEditQuote\rModel = PAStatementValidation",
                "figure": "RoundedRectangle"
            },
            {
                "key": "Start",
                "category": "begin",
                "type": "Start",
                "location": "169 124",
                "size": "57 55",
                "text": "",
                "tooltip": "Datasource=",
                "break": "false",
                "Properties": {
                    "Name": "Start"
                }
            },
            {
                "key": "Count.6",
                "category": "image",
                "type": "Count",
                "location": "172 378",
                "size": "49 49",
                "text": "# of Sele QA’s",
                "tooltip": "Number of Sele Question Answers=Statement Sele QA Where Statement Sele Answer Required equals Y",
                "break": "false",
                "Properties": {
                    "Variable": "[:000013]",
                    "Name": "Count",
                    "Message": "Count",
                    "ShortName": "Statement Sele QA",
                    "Operand1": "equals",
                    "Value1": "Y",
                    "CountType1": "All",
                    "DecShortName": "Statement Sele Answer Required",
                    "DataBase": "DB1",
                    "Table": "SHSeleQuestions",
                    "XMLPath": "DB1\\SHSeleQuestions",
                    "DecXMLPath": "DB1\\SHSeleQuestions\\ResponseReqInd"
                }
            },
            {
                "key": "Multiple Decisions",
                "category": "Decision",
                "type": "DecPlus",
                "location": "169 508",
                "size": "75 56",
                "text": "If no required answers given",
                "tooltip": "Number of Sele Question Answers is greater than 0",
                "break": "false",
                "Properties": {
                    "DecisionInd": "True",
                    "Variable1": "[:000013]",
                    "Operand1_1": "is greater than",
                    "Value1_1": "0",
                    "Name": "DecPlus",
                    "Variable2": "[:000015]",
                    "Operand1_2": "equals",
                    "Value1_2": "0"
                }
            },
            {
                "key": "Finish",
                "category": "end",
                "type": "Finish",
                "location": "172 625",
                "size": "57 55",
                "text": "",
                "tooltip": "",
                "break": "false",
                "Properties": {
                    "Name": "Finish"
                }
            },
            {
                "key": "Status",
                "category": "image",
                "type": "Status",
                "location": "313 508",
                "size": "53 49",
                "text": "HOST003",
                "tooltip": "Warning=HOST003 - All Questions must be answered on the Statement Page.",
                "break": "false",
                "Properties": {
                    "Name": "Status",
                    "Message": "Validation.IValidation",
                    "StatusCode": "PADriver002",
                    "StatusType": "Error",
                    "StatusMessage": "All Questions must be answered on the Statement Page.",
                    "StatusPage": "PAStatement.aspx",
                    "Unique": "False"
                },
                "Unique": "False"
            },
            {
                "key": "Finish.14",
                "category": "end",
                "type": "Finish",
                "location": "461 508",
                "size": "57 55",
                "text": "Stop Model",
                "tooltip": "",
                "break": "false",
                "Properties": {
                    "Name": "Finish",
                    "Termination": "StopModel"
                }
            },
            {
                "key": "Count",
                "category": "image",
                "type": "MultiCount",
                "location": "172 252",
                "size": "49 49",
                "selected": "true",
                "text": "Statement Answer",
                "tooltip": "=",
                "break": "false",
                "Properties": {
                    "Variable": "[:000015]",
                    "Name": "MultiCount",
                    "Message": "MultiCount",
                    "ShortName": "Statement Answer",
                    "CountType1": "All",
                    "ShortName1": "Statement Answer",
                    "Operand1_1": "does not equal",
                    "Item": "1",
                    "XMLDoc": "PagePolicyData",
                    "XMLPath": "PagePolicyData\\ValidationMessage\\PageContent\\ACORD\\PersAutoLineBusiness\\QuestionAnswer\\YesNoCd",
                    "XMLPath1": "PagePolicyData\\ValidationMessage\\PageContent\\ACORD\\PersAutoLineBusiness\\QuestionAnswer\\YesNoCd",
                    "XMLCondPath": "Root\\PagePolicyData\\ValidationMessage\\PageContent\\ACORD\\PersAutoLineBusiness\\QuestionAnswer{((YesNoCd != ''))}\\YesNoCd"
                }
            },
            {
                "category": "Comment",
                "location": "450 50",
                "size": "150 38",
                "figure": "RoundedRectangle",
                "text": "Summary Check"
            }
        ],
        "RulesArray": {
            "0": "Check Bypass",
            "1": "Bypass Edorsement",
            "2": "Statement Questions"
        }
    }
于 2013-03-20T06:32:52.853 回答