传递对象数组从WCF到PHP - 提取信息 [英] Passing array of objects from WCF to PHP - extracting the info

查看:158
本文介绍了传递对象数组从WCF到PHP - 提取信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个C#WCF服务,它负责从数据库中提取信息并传送信息的简单对象数组到PHP站点的方法。

I have a method in a C# WCF service, which is responsible for extracting information from a database and then passing that information as an array of simple objects to a PHP site.

public class Person
{
    public int Id;
    public string Name;
    public string Lastname;
    public string Phone;
}
...
public Person[] GetPerson(){...}

由于我不是很好用PHP,我的问题是:我如何提取从阵列在事物的PHP结束的信息?最常见的错误,我得到的是:不能使用类型stdClass的对象为数组。我已经尝试了许多不同的事情。简单的PHP code片段:

Since I'm not really good with PHP, my problem is: How do I extract the information from the array at the PHP end of things? The most common error that i get is: Cannot use object of type stdClass as array. I have tried many different things. The simple PHP code fragment:

<?php
$client = new SoapClient("http://localhost:62532/Service1.svc?wsdl");

$ws = $client->GetPerson();
$wsr = $ws->GetPersonResult;

for($i = 0; $i < count($wsr); $i++)
{
echo $wsr[$i]->Id . "\n";
echo $wsr[$i]->Name . "\n";
echo $wsr[$i]->Lastname . "\n";
echo $wsr[$i]->Phone . "\n";
} 
?>

不工作。当我打电话:

Does not work. When i call:

的print_r($ WSR);

要检查的方法返回我会得到什么结果:

to check the result of what the method returned i get:

stdClass Object 
( [Person] => Array ( 
[0] => stdClass Object ( 
[Id] => 1 [Name] => John [Lastname] => Abc [Phone] => 759687364 ) 
[1] => stdClass Object ( 
[Id] => 2 [Name] => Joe [Lastname] => Def [Phone] => 487512654 ) 
[2] => stdClass Object ( 
[Id] => 3 [Name] => Mike [Lastname] => Ghi [Phone] => 874587918 ) 
[3] => stdClass Object ( 
[Id] => 5 [Name] => Nick [Lastname] => Jkl [Phone] => 000000000) 
) 
)

因此​​,基于结果,WCF和PHP之间的全部数据交换工作正常,因为这些都是正确的结果,但我不知道如何轻松(沿着我上面试过线东西.. )从正在返回的数组中访问它们。

So based on the result, the entire data exchange between WCF and PHP works fine, as those are the correct results, but i don't know how to easily (something along the lines of what I've tried above..) access them from within the array that is being returned.

我已经搜查了不少解决的办法,但没有发现任何东西,将工作。任何帮助将大大AP preciated,谢谢。

I've searched quite a bit for a solution, but haven't found anything that would work. Any help would be greatly appreciated, thanks.

编辑:好了,解决的办法是:

Ok, so the solution is:

for($i = 0; $i < count($wsr->Person); $i++)
{
echo $wsr->Person[$i]->Id . "\n";
echo $wsr->Person[$i]->Name . "\n";
echo $wsr->Person[$i]->Lastname . "\n";
echo $wsr->Person[$i]->Phone . "\n";
} 

谢谢您的回答。

推荐答案

使用 $ wsr-&GT;人[$ i] - 方式&gt;标识

这篇关于传递对象数组从WCF到PHP - 提取信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆