空关联数组SOAP类型转换 [英] Empty associative array SOAP type conversion

查看:79
本文介绍了空关联数组SOAP类型转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个客户端服务器方案,其中PHP的SoapClient类进行了类型转换,无法分辨一个空数组是关联数组还是数值数组,因此默认为数值。

I have a client server scenario where the type conversion did by the SoapClient class in PHP, cannot tell wether an empty array is associative or numeric, and so defaults to numeric.

所有公开的函数都使用基本类型,而不使用类。

All exposed functions use basic types, no classes.

关联数组,例如 array( something => 123)被转换为地图数据类型。但是,当同一数组为空时,例如 array(),它将转换为Ruby端的数组。将类型强制转换为对象(object)array()将在Ruby端生成结构数据类型。

An associative array such as array("something"=>123) gets converted to a map data type. However, when the same array is empty, such as array(), it gets converted to an array on the Ruby side. Type casting to object (object)array() will result in a struct data type on the Ruby side.

参数稍微复杂一点,但不像上面那么简单:

The argument is a bit more complex, not as simple as above:

array(
    "options"=>array(
        "plans"=>array(
            0=>array(
                "name"=>"abc",
                "product_options"=>array(
                    "optional_key_determines_associative_array_data_type"=>0,
                ),
            ),
        ),
    ),
);

如果 product_options 下的数组为如果为空,它将转换为Ruby中的数组而不是映射。再次,在PHP中对对象进行类型转换会在Ruby中生成结构。

If the array under "product_options" is empty, it gets converted to an array in Ruby, instead of a map. Once again, type casting to object in PHP results in a struct in Ruby.

我可以在PHP方面做什么以使空的关联数组结束

PHP 5.3.3(使用SoapClient)。
使用Action Web Service的Ruby 1.8.7,Rails 2.3.2。

PHP 5.3.3, using SoapClient. Ruby 1.8.7, Rails 2.3.2 using Action Web Service.

推荐答案

您可以将数组包装在 SoapVar 类使用 APACHE_MAP 作为编码参数。像这样:

You can wrap your array in a SoapVar class with APACHE_MAP as encoding parameter. Like This:

array(
    "options"=>array(
        "plans"=>array(
            0=>array(
                "name"=>"abc",
                "product_options"=> new SoapVar(array(), APACHE_MAP),
            ),
        ),
    ),
);

这篇关于空关联数组SOAP类型转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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