PHP SoapClient 将数组转换为字符串

标签 php arrays string soap

另一个 SOAP 问题 - 我有一个大的多维数组,当使用 print_r 时回显很好(例如,您可以看到所有数据)。当我使用

时出现问题
SOAPClient->__soapCall('Function', array('paramaters' => $feedUpload));

这实际上返回了一个如下所示的 xml:(使用 __getLastRequest)

<soap-env:envelope xmlns:ns1="http://www.property24.com/prosol/P24Feed" xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/">
    <soap-env:body>
        <ns1:uploadlistings>
            <ns1:feedupload>
                <ns1:version>1</ns1:version>
                <ns1:usertoken>
                    <ns1:token>3c7b39ea-c10b-451f-95bf-5118d84fb089</ns1:token>
                </ns1:usertoken>
                <ns1:command>UPLOAD</ns1:command>
                <ns1:compress>None</ns1:compress>
                <ns1:listings>
                    <ns1:listing>
                        <ns1:listingnumber>361000001</ns1:listingnumber>
                        <ns1:propertycategory>SR</ns1:propertycategory>
                        <ns1:listingdata>Array</ns1:listingdata>
                        <ns1:listingtype>A</ns1:listingtype>
                    </ns1:listing>
                </ns1:listings>    
            </ns1:feedupload>    
        </ns1:uploadlistings>
    </soap-env:body>
</soap-env:envelope>

如您所见,对于 ListingData,它返回“Array”。这是数组架构:

Array
(
    [parameters] => Array
        (
            [FeedUpload] => Array
                (
                    [Version] => 1
                    [UserToken] => Array
                        (
                            [Token] => 5ece25e7-77d9-4dbf-8b8f-e047759ab8f4
                        )

                    [Command] => UPLOAD
                    [Compress] => None
                    [Listings] => Array
                        (
                            [Listing] => Array
                                (
                                    [PropertyCategory] => SR
                                    [ListingNumber] => 361000001
                                    [ListingType] => A
                                    [ListingData] => Array
                                        (
                                            [MandateDetails] => Array
                                                (
                                                    [ListingNumber] => 361000001
                                                    [ListingType] => A
                                                    [MandateType] => O
                                                    [ClosedUserGroup] => C
                                                    [MarketCode] => A
                                                    [ListPrice] => 111000
                                                    [OccupationDate] => 
                                                    [OffMarketDate] => 
                                                    [OnMarketSince] => 
                                                    [ExpiryDate] => 2011-07-13T09:56:14Z
                                                    [ListDate] => 2011-07-13T09:51:14Z
                                                    [UpdateDate] => 2011-07-13T09:51:14Z
                                                    [VirtualTourUrl] => 
                                                    [ActualDirections] => 
                                                    [ShowHouseDirection] => 
                                                    [ViewComments] => 
                                                    [InternetComments] => Excellent stand situated on the flood plane with large riverine trees and great mountain views.   The estate is situated along the world renowned Blyde River and is 394 ha in extent with only 154 sites on 4000 square metres.  The estate has an array of plains game such as antelope, giraffe and wildebeest as well as hippo and crocodile.     The riverine flood plain provides great birding opportunities such as the Pels fishing owl. There is a restaurant and clubhouse that serves meals and cocktails and offers  
                                                )

                                            [PropertyDetails] => Array
                                                (
                                                    [PropertyCategory] => SR
                                                    [PropertyType] => SRX
                                                    [Status] => ACTV
                                                    [Province] => Eastern Cape
                                                    [Town] => Aberdeen
                                                    [Suburb] => Balvinie
                                                    [StreetName] => Test Street
                                                    [StreetNumber] => 5
                                                    [PostalCode] => 0123
                                                    [ErfSize] => 1200
                                                    [HouseSize] => 
                                                    [Age] => 
                                                    [OwnerType] => G
                                                    [VATRegistered] => false
                                                    [MunicipalRatesAndTaxes] => 0
                                                    [MunicipalImprovementsValue] => 0
                                                    [MunicipalLandValue] => 0
                                                    [MunicipalTotalValue] => 0
                                                    [StandNumber] => 
                                                    [StandNumberSubdivided] => 
                                                    [PortionNumber] => 
                                                    [OwnerShipType] => 
                                                )

                                            [ResidentialDetails] => Array
                                                (
                                                    [NoOfBathrooms] => 2
                                                    [BathroomDescription] => 
                                                    [NoOfBedrooms] => 6
                                                    [BedroomDescription] => 
                                                    [NoOfKitchens] => 2
                                                    [KitchenDescription] => 
                                                    [NoOfReceptionRooms] => 2
                                                    [ReceptionRoomDescription] => 
                                                    [NoOfStudies] => 1
                                                    [StudiesDescription] => 
                                                    [NoOfDomesticBathrooms] => 2
                                                    [NoOfDomesticRooms] => 0
                                                    [DomesticRoomsDescription] => 
                                                    [NoOfGarages] => 0
                                                    [GarageDescription] => 
                                                    [NoOfOutsideToilets] => 0
                                                    [Coverage] => 0
                                                    [Pool] => false
                                                    [PoolDescription] => 
                                                    [Flatlet] => 
                                                    [FlatletDescription] => 
                                                    [FlatletSize] => 
                                                    [EstablishedGarden] => 
                                                    [OutBuildingSize] => 
                                                    [NoOfCarports] => 0
                                                    [CarportsDescription] => 
                                                    [ParkingBayNumber] => 
                                                    [Parking] => 
                                                    [ParkingDescription] => 
                                                    [BusinessRights] => 
                                                    [HeightRestrictions] => 
                                                    [CommonFeatures] => 
                                                    [NumberOfShares] => 
                                                    [FacingOptions] => 
                                                    [KitchenOptions] => 
                                                    [FeatureOptions] => 
                                                    [SpecialFeatureOptions] => 
                                                    [WallOptions] => 
                                                    [WindowOptions] => 
                                                    [StyleOptions] => 
                                                    [TemperatureControlOptions] => 
                                                    [SecurityOptions] => 
                                                    [RoofOptions] => 
                                                    [RoomOptions] => 
                                                    [PoolOptions] => 
                                                    [BathroomOptions] => 
                                                )

                                            [AgentDetails] => Array
                                                (
                                                    [InternetAgentName] => Ricky Duckworth
                                                    [InternetAgentPhoneNumber] => 0157931534
                                                    [InternetAgentEmailAddress] => ricky@propertylogic.net
                                                    [InternetAgentSMSNumber] => 0796057834
                                                    [ListingAgentCode] => CN21
                                                    [ListingAgencyCode] => CWP021
                                                )
                                        )
                                )
                        )
                )
        )
)

如您所见,数组结构良好。这就像 SoapRequest 已经进入数组并停止了。我也收到通知了

Notice: Array to string conversion in /var/www/vhosts/propertylogic.net/httpdocs/soap_feed/property24/add_property.php on line 178

SOAPCall 行。

非常感谢!

编辑

[编辑]好吧,基本上 SOAP 服务器要求该部分是原始 xml,所以我不得不用字符串替换数组——这是一种愚蠢的做事方式,但现在错误消息是有道理的! (无法回答我自己的问题)。

最佳答案

您最好生成并使用 WSDL 来创建 SOAP 客户端并在其中定义复杂类型。这样,每个 SOAP 类型都将以自然的方式转换为 PHP 类型(在您的示例中,它将是一个对象数组)。

或者你可以像你已经做的那样用字符串替换数组,尽管这是一个肮脏的魔法:)

关于PHP SoapClient 将数组转换为字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6675765/

相关文章:

php - ASIHTTPRequest 将 json 发送到 php 服务器

c# - 使用单循环在数组中查找重复项

C memcpy 函数内 2D 数组到 3D 数组

java - 从字符串数组中删除一个字符

php - fgetcsv() : first row as key

php - 无法在 Laravel Model 的 create 方法中引用静态字段

jquery - 如何获取数组中元素的CSS值?

c++ - 取一串字母并将它们放入数组中

作用于一串数字的python map函数

php - 从数组生成 jquery 列表