Web Services 如何查找Web服务调用中参数的错误值

amrnrhlw  于 2022-11-15  发布在  其他
关注(0)|答案(1)|浏览(178)

当我对WebMethod进行 AJAX 调用时,得到服务器错误:该值
值“System.Collections.Generic.Dictionary "2 [System.String,System.Object]”不是“KBO.StoreLib.RootNode”类型,因此不能用于此泛型集合。参数名:价值观
电话很简单...

static AllocationQuery(url: string, method: string, AjaxBookGenieParams:AjaxBookGenieParams, allowWindowClose : boolean) {
    if (this.kboAjaxIsActive) return; // prevent double clicks - racing
    this.kboAjaxIsActive = true;
    const jsonString = JSON.stringify({AjaxBookGenieParams: AjaxBookGenieParams,}) ;
    let myUrl = url + method;
    $.ajax({
        type: "POST",
        url: myUrl,
        data: jsonString,
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        async: allowWindowClose, //blocks window close
        success: this.Allocatiom_Success,
        error: this.Allocation_Error
    });
}

Web方法也很简单...

[WebMethod]
public AjaxBookGenieParams StartNewAllocation(AjaxBookGenieParams AjaxBookGenieParams)
{
    StaticState.SetIsWebApi();
    AjaxBookGenieParams = BookGenieHandler.BuildAllocationData(AjaxBookGenieParams);
    AjaxBookGenieParams = BookGenieHandler.AllocateNextTitle(AjaxBookGenieParams);
    return AjaxBookGenieParams;
}

关联的ajaxcall.json是...

{"AjaxBookGenieParams":{"AgeCandidates":[],"Book":{"ISBN":"","ProductId":0,"ImageUrl":"","Title":"","Price":0,"Quantity":0,"AgeId":0},"AllocatedBooks":[],"BookGenieParams":{"AllocatedQuantity":0,"AllocatedSubTotal":0,"AllocatedTitles":0,"AllocationBudget":200,"BooksPerTitle":5,"CustomerGuid":"","CustomerId":0,"DefaultBooksPerTitle":5,"MinimumBudget":200,"MoveToCartSubTotal":0,"MoveToCartCount":0,"ReDisplayBreak":10,"SelectedCategories":[],"UserBooksPerTitle":0},"Data":"","ProductFilterParams":{"RootNodes":[{"Id":50,"Name":"Ages","GroupType":"ages","NodeCategories":[{"Id":38,"Name":"Ages 0 to 2","Count":54,"Selected":"off","Description":"","GroupCats":[]},{"Id":34,"Name":"Ages 3 to 5","Count":536,"Selected":"off","Description":"","GroupCats":[]},{"Id":35,"Name":"Ages 6 to 8","Count":471,"Selected":"off","Description":"","GroupCats":[]},{"Id":37,"Name":"Ages 9 to 12","Count":1126,"Selected":"off","Description":"","GroupCats":[]},{"Id":36,"Name":"Young Adult","Count":803,"Selected":"off","Description":"","GroupCats":[]}],"Description":"Books By Age","ToolTip":"","Selected":"off","__expanded__":false}],"FilterGuid":"","AgeRange":{"Min":1,"Max":18,"From":3,"FromInit":3,"To":12,"ToInit":12},"SelectedAges":[],"FilterCategories":{},"ResetFilter":"false"},"Request":"StartAllocationToCart"}}

由于初始负载json是...

{
"AgeCandidates": [
    {
        "AllocationCandidates": [],
        "AgeId": 0
    }
],
"Book": {
    "AgeId": 0,
    "ImageURL": "",
    "ISBN": "",
    "Price": 0.0,
    "ProductId": 0,
    "Quantity": 0,
    "Title": ""
},
"AllocatedBooks": [],
"BookGenieParams": {
    "AllocatedQuantity": 0,
    "AllocatedSubTotal": 0.0,
    "AllocatedTitles": 0,
    "AllocationBudget": 200,
    "BooksPerTitle": 3,
    "CustomerGuid": "",
    "CustomerId": 0,
    "DefaultBooksPerTitle": 5,
    "MinimumBudget": 200,
    "MoveToCartSubTotal": 0.0,
    "MoveToCartCount": 0,
    "ReDisplayBreak": 10,
    "SelectedCategories": [],
    "UserBooksPerTitle": 0
},
"Data": "",
"ProductFilterParams": {
    "RootNodes": [
        {
            "Id": 50,
            "Name": "Ages",
            "GroupType": "ages",
            "NodeCategories": [
                {
                    "Id": 38,
                    "Name": "Ages 0 to 2",
                    "Count": 54,
                    "Selected": "off",
                    "Description": "",
                    "GroupCats": []
                },
                {
                    "Id": 34,
                    "Name": "Ages 3 to 5",
                    "Count": 536,
                    "Selected": "off",
                    "Description": "",
                    "GroupCats": []
                },
                {
                    "Id": 35,
                    "Name": "Ages 6 to 8",
                    "Count": 471,
                    "Selected": "off",
                    "Description": "",
                    "GroupCats": []
                },
                {
                    "Id": 37,
                    "Name": "Ages 9 to 12",
                    "Count": 1126,
                    "Selected": "off",
                    "Description": "",
                    "GroupCats": []
                },
                {
                    "Id": 36,
                    "Name": "Young Adult",
                    "Count": 803,
                    "Selected": "off",
                    "Description": "",
                    "GroupCats": []
                }
            ],
            "Description": "Books By Age",
            "ToolTip": "",
            "__expanded__": false,
            "Selected": "off"
        }
    ],
    "FilterGuid": "",
    "AgeRange": {
        "Min": 1,
        "Max": 18,
        "From": 3,
        "FromInit": 3,
        "To": 12,
        "ToInit": 12
    },
    "SelectedAges": [],
    "FilterCategories": {},
    "ResetFilter": "false"
},
"Request": ""

}
我希望不会抛出错误。我的C#类一定有问题,但我无法解决。它们可以在以下位置找到:https://www.dropbox.com/sh/ggsg552do3f21ca/AACv0wGZ18o0yG7heDnenOQ-a?dl=0我试图找出我的C#类在哪里有问题。谢谢Abbott

ibrsph3r

ibrsph3r1#

当Asp.net涉及到复杂的json时,www. example. comWebMethods是相当挑剔的。我通过创建一个json字符串的json对象来解决这个问题,我在两端用转换器处理了这个对象。下面是类...

export class AjaxBookStringParams {
AgeCandidates: string = ""; // AllocationCandidates by age to-from server
BookToDelete:  string = ""; // Used to delete an allocated book
AllocatedBooks:  string = "";; // placeholder for to-from server - grid display
BookGenieParams: string = "";
Data: string = "";
ProductFilterParams:  string = "";
Request: string = "";

它让我可以专注于我自己愚蠢的/粗心的编码和打字错误;-}
谢谢大家的帮助。雅培

相关问题