简体   繁体   English

无法将类型为stdClass的对象用作数组

[英]Cannot use object of type stdClass as array

I am trying to fetch an array from a .net WebService and echo it, but it keeps saying: "Cannot use object of type stdClass as array" if I use var dump i get this so the array is in the variable. 我试图从.net WebService获取一个数组并回显它,但它一直说:“不能将stdClass类型的对象用作数组”,如果我使用var dump我得到了这个,所以数组在变量中。 Do i need to do something special to it because it's from a .net webservice??? 我是否需要对它进行特殊处理,因为它来自.net Web服务??? I have no experince in C#. 我没有C#的经验。 The first function is working just fine. 第一个功能运行正常。

object(stdClass)#4 (1) { ["string"]=> array(4) { [0]=> string(3) "Ivo" [1]=> string(6) "Peter" [2]=> string(5) "Simon" [3]=> string(6) "Michel" } } object(stdClass)#4(1){[“”“] =>数组(4){[0] =>字符串(3)” Ivo“ [1] =>字符串(6)” Peter“ [2] = >字符串(5)“ Simon” [3] =>字符串(6)“ Michel”}}

<?php

$client = new SoapClient("http://xavier.monkees.com/XavierService.svc?singleWsdl");
$response = $client->CheckName(array(
                                "name" => "$naam"));


$response_array = $client->GetNames()->GetNamesResult;

echo $response_array[1];
?>

Looking at the dump of your object, it looks like the first subscript is "string" 查看对象的转储,看起来第一个下标是“字符串”

object(stdClass)#4 (1) { ["string"]=> array(4) { [0]=> string(3) "Ivo" [1]=> string(6) "Peter" [2]=> string(5) "Simon" [3]=> string(6) "Michel" } }

Try 尝试

$response_array = $client->GetNames()->GetNamesResult->string[1];

or 要么

$response_array = $client->GetNames()->GetNamesResult["string"][1];

暂无
暂无

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

相关问题 为什么编译器无法推断出对象数组类型? - Why Compiler cannot infer the object array type? System.Array.SetValue - 对象不能存储在这种类型的数组中 - System.Array.SetValue - Object cannot be stored in an array of this type Object 不能存储在这种类型的数组中。 MVC c# 中的问题 - Object cannot be stored in an array of this type. issue in MVC c# MakeGenericType()实际上创建一个对象,而我不能使用该类型的方法 - MakeGenericType() actually makes an object, and I cannot use the type's methods 不能将object用作方法的默认参数类型 - Cannot use object as a type of method's default parameter C#在使用AutocompleteStringCollection时无法将对象类型数组转换为字符串类型数组 - C# cannot convert object type array to string type array while using AutocompleteStringCollection 在C#中解析stdClass对象 - Parse stdClass object in C# 如何解决“无法将当前的 JSON 数组反序列化为类型,因为该类型需要 JSON object 才能正确反序列化。” - How to solve “Cannot deserialize the current JSON array into type because the type requires a JSON object to deserialize correctly.” 无法将[]的索引应用于从NHibernate返回的对象数组的表达式类型“对象” - Cannot apply indexing with [] to an expression type 'object' for Object Array returned from NHibernate Twitter:无法将JSON数组反序列化为对象,因为该类型需要JSON对象 - Twitter : Cannot deserialize a JSON array into an object because the type requires a JSON object
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM