简体   繁体   English

“对象”类型的对象无法转换为“数组”类型

[英]Object of type 'Object' cannot be converted to type 'Array'

I have read about this error many articles, I have tried many solutions but nothing is working! 我已经阅读了很多有关此错误的文章,我尝试了许多解决方案,但是没有任何效果! I am stuck with this error since 3 days I hope someone can help me, thanks! 自3天以来,我一直遇到这个错误,希望有人可以帮助我,谢谢! What I'm doing is calling my webservice from my mypage.aspx through two ways: 我正在做的是通过两种方式从mypage.aspx调用Web服务:

A-) 一种-)

MyWebservice.MyWebMethod("test",LunchMyFunction);

function LunchMyFunction(response) {
   alert(response); // [object Object] 
   var gridView = $find('<%= MyGridView.ClientID %>');
   gridView.set_dataSource(response);
   gridView.dataBind();
}

Here the gridview is filled properly and everything is ok. 在这里,gridview正确填充,一切正常。

B-) B-)

$.ajax({
         type: "POST",
         url: 'MyWebservice.asmx/MyWebMethod',
         data:{ testVal : "test" },
         success: function (response) {
            alert(response); // [object XMLDocument]
            var gridView = $find('<%= MyGridView.ClientID %>');
            try {
            gridView.set_dataSource(response);
            } catch (err) {
               alert(err);
            }
            gridView.dataBind();
         },
         error: function (err) { alert(err.statusText); }
});

Here my web method is completing it's work but when it comes to setdatasource : an error is thrown: Sys.ArgumentTypeException: Sys.ArgumentTypeException: Object of type 'Object' cannot be converted to type 'Array'. 在这里,我的Web方法正在完成其工作,但是当涉及setdatasource时:引发错误: Sys.ArgumentTypeException:Sys.ArgumentTypeException:类型为“ Object”的对象无法转换为类型为“ Array”的对象。 Parameter name: value 参数名称:值

I thought that this error is thrown because response type is different in both cases, so I have tried to set types as json to return [object Object]. 我认为抛出此错误是因为两种情况下的响应类型都不同,因此我尝试将类型设置为json以返回[object Object]。 After returning Object the method still throws the same error. 返回Object之后,该方法仍会引发相同的错误。 I have tried ScriptMode="Release" in my ToolkitScriptManager which is in my Master page not in mypage.aspx, but nothing have changed. 我已经在我的母版页而不是mypage.aspx中的ToolkitScriptManager中尝试了ScriptMode =“ Release”,但是没有任何更改。

<cc1:ToolkitScriptManager ScriptMode="Release" ID="ToolkitScriptManager1" AsyncPostBackTimeout="600" EnablePartialRendering="true" EnablePageMethods="true" runat="server">
    <Services>
        <asp:ServiceReference path="MyWebservice.asmx" />
    </Services>
    <Scripts>
        <asp:ScriptReference path="~/JavaScript/WebKitFix.js" />
    </Scripts>
 </cc1:ToolkitScriptManager>

The assembly of cc1 is AjaxControlToolkit, and mypage.aspx is included in Master Page. cc1的程序集是AjaxControlToolkit,而mypage.aspx包含在“母版页”中。 Any idea about what could be the problem? 关于可能是什么问题的任何想法? How can I resolve it? 我该如何解决?

Finally, after searching I discovered that in the second method response is: 最后,在搜索之后,我发现第二种方法的响应是:

{"d":[{"__type":"UploadedFile","Success":"Success","UploadedURL":"Uploaded URL"}]}

while what I need was response.d to return this: 而我需要的是response.d返回此:

[{ "__type": "UploadedFile", "Success": "Success", "UploadedURL": "Uploaded URL"}]

That was my error, thank you 那是我的错,谢谢

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何修复Sys.ArgumentTypeException:无法将“对象”类型的对象转换为“功能”类型 - How to fix Sys.ArgumentTypeException: Object of type 'Object' cannot be converted to type 'Function' 无法将类型为“ Infragistics.Web.UI.SlideFadeAnimation”的对象转换为类型为“ Sys.Component”的对象 - Object of type 'Infragistics.Web.UI.SlideFadeAnimation' cannot be converted to type 'Sys.Component' NetSuite:无法从数组访问对象类型内的对象 - NetSuite: Cannot access object inside object type from array 迭代数组中的数组时出错:“找不到支持 object '[object Object]' 类型为 'object' 的不同。” - Error when iterating over array within array: “Cannot find a differ supporting object '[object Object]' of type 'object'.” 将数组转换为对象类型 - Convert an Array into object type 对象数组中的类型转换 - Type conversion in the object array 找不到支持“object”类型的 object“[object Object]”的不同,但它已经是一个数组 - Cannot find a differ supporting object '[object Object]' of type 'object' , but it's already an array 错误:找不到支持 object '[object Object]' 类型 'object' 的差异 - Err: Cannot find a differ supporting object '[object Object]' of type 'object' 在角度6中找不到类型为“对象”的其他支持对象“ [对象对象]” - Cannot find a differ supporting object '[object Object]' of type 'object' in angular 6 检查 object 是否属于类型(类型定义为数组) - TypeScript - Check if object is of type (type is defined as array) - TypeScript
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM