无法使用 ksoap2 在 Android 中序列化错误

2024-02-06

我有一个 magento soap v2 api 网络服务。我可以使用 ksoap2 从 android 进行通信。下面给出了我尝试过的 xml 和编码。

------------XML API------------

<operation name="catalogProductCreate">
<documentation>Create new product and return product id</documentation>
<input message="typens:catalogProductCreateRequest"/>
<output message="typens:catalogProductCreateResponse"/></operation>


<message name="catalogProductCreateRequest">
<part name="sessionId" type="xsd:string"/>
<part name="type" type="xsd:string"/>
<part name="set" type="xsd:string"/>
<part name="sku" type="xsd:string"/>
<part name="productData" type="typens:catalogProductCreateEntity"/>
<part name="storeView" type="xsd:string"/>
</message>


<complexType name="catalogProductCreateEntity">
<all>
<element name="categories" type="typens:ArrayOfString" minOccurs="0"/>
<element name="websites" type="typens:ArrayOfString" minOccurs="0"/>
<element name="file" type="typens:catalogProductImageFileEntity" minOccurs="0"/
<element name="name" type="xsd:string" minOccurs="0"/>
<element name="description" type="xsd:string" minOccurs="0"/>
<element name="short_description" type="xsd:string" minOccurs="0"/>
<element name="weight" type="xsd:string" minOccurs="0"/>
<element name="status" type="xsd:string" minOccurs="0"/>
</all>
</complexType>

<complexType name="catalogProductImageFileEntity">
<all>
<element name="content" type="xsd:string"/>
<element name="mime" type="xsd:string"/>
<element name="name" type="xsd:string" minOccurs="0"/>
</all>
</complexType>

------------主类---------

request = new SoapObject(NAMESPACE,"catalogProductCreate");

        request.addProperty("sessionId", sessionId);

        request.addProperty("type", "simple");
        request.addProperty("set", "4");
        request.addProperty("sku", sku.toString());

        //-----use Kvm Serializable class to serialize the key value data-------

        CreateProductKVMserialize createproductkvm = new CreateProductKVMserialize();

        createproductkvm.Name = name;
        createproductkvm.Description = description;
        createproductkvm.ShortDescription = shortdescription;

        createproductkvm.Weight = weight;
        createproductkvm.Status = "1";
        createproductkvm.Price = price;

        PropertyInfo pi = new PropertyInfo();
        pi.setName("productData");
        pi.setValue(createproductkvm);
        pi.setType(createproductkvm.getClass());
        request.addProperty(pi);

        env.setOutputSoapObject(request);

        env.addMapping(NAMESPACE, "productData",new CreateProductKVMserialize().getClass());

        androidHttpTransport.call("", env);
        Object product_create = env.getResponse();
        Log.d("mainactivity "," "+product_create.toString());

--------------创建ProductKVM序列化类------------

public class CreateProductKVMserialize implements KvmSerializable{

public String[] Categories; // this array i cant send it shows cannot serialize error
public String Name;
public String Description;
public String ShortDescription;
public String Weight;
public String Status;
public String Price;

public CreateProductKVMserialize(){}

public CreateProductKVMserialize(String[] categories,String name, String description, String shortdescription, String weight,String status,String price) {

    Categories = categories;
    Name = name;
    Description = description;
    ShortDescription = shortdescription;
    Weight = weight;
    Status= status;
    Price = price;
}

@Override
public Object getProperty(int arg0) {
    // TODO Auto-generated method stub
     switch(arg0)
        {
        case 0:
            return Categories;
        case 1:
            return Name;
        case 2:
            return Description;
        case 3:
            return ShortDescription;
        case 4:
            return Weight;  
        case 5:
            return Status;  
        case 6:
            return  Price ; 

        }

        return null;

}

@Override
public int getPropertyCount() {
    // TODO Auto-generated method stub
    return 7;
}

@Override
public void getPropertyInfo(int index, Hashtable arg1, PropertyInfo info) {
    // TODO Auto-generated method stub

     switch(index)
        {
        case 0:
            info.type = PropertyInfo.VECTOR_CLASS;
            info.name = "categories";
            break;
        case 1:
            info.type = PropertyInfo.STRING_CLASS;
            info.name = "name";
            break;
        case 2:
            info.type = PropertyInfo.STRING_CLASS;
            info.name = "description";
            break;
        case 3:
             info.type = PropertyInfo.STRING_CLASS;
             info.name = "short_description";
            break;
        case 4:
             info.type = PropertyInfo.STRING_CLASS;
             info.name = "weight";
            break;
        case 5:
             info.type = PropertyInfo.STRING_CLASS;
             info.name = "status";
            break;
        case 6:
             info.type = PropertyInfo.STRING_CLASS;
             info.name = "price";
            break;

        default:break;
        }
}

@Override
public void setProperty(int index, Object value) {
    // TODO Auto-generated method stub

    switch(index)
    {
    case 0:
        Categories = (String[])value;
        break;
    case 1:
        Name = value.toString();
        break;
    case 2:
        Description = value.toString();
        break;
    case 3:
        ShortDescription = value.toString();
        break;
    case 4:
        Weight = value.toString();
        break;
    case 5:
        Status = value.toString();
        break;
    case 6:
        Price = value.toString();
        break;

    default:
        break;
    }
 }

}

但问题是我无法发送复杂类型的数据(例如:Array)并且 直到“catalogProductCreateEntity”只有我可以通信,如果我发送数组数据,它会显示错误“无法序列化..”。如何以“typens:ArrayOfString”形式发送数据,以及如何与“catalogProductImageFileEntity”(“catalogProductCreateEntity”中的名称类型)通信。


None

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

无法使用 ksoap2 在 Android 中序列化错误 的相关文章

随机推荐

  • 散列和索引有什么区别?

    我研究了 DBMS 中的哈希 可扩展 线性 和 DBMS 中的索引 稀疏 密集 基于辅助键的索引等 但我无法理解哈希和索引之间的区别 这两种技术是一起使用还是单独使用 我很困惑 因为这两种技术的目的似乎都是为了让我们能够快速检索数据 所以我
  • EL 语法错误是 en

    JSP页面中的以下语句在第一个附近遇到错误equals出现这种情况 请问是什么原因 如何解决 请尽快纠正 fn length updateStock todayDimensionStones i count DimensionStones
  • 以编程方式获取当前页面

    在 JSF 支持 Bean 托管 Bean 焊接 Bean 无关紧要 中 我可以通过调用获取客户端所在的上下文路径 FacesContext ctx FacesContext getCurrentInstance String path c
  • C# 线程问题和最佳实践

    这是我第一次在 C 应用程序中使用线程 基本上它是一个应用程序 用于检查列表中的一堆网站是死是活 这是我第一次尝试使用多线程 public void StartThread string URL int no Thread newThrea
  • application(_:didFinishLaunchingWithOptions:)' 几乎符合可选要求

    安装 Xcode 8 beta 6 后 我收到一条警告 实例方法 application didFinishLaunchingWithOptions 几乎匹配协议 UIApplicationDelegate 的可选要求 applicatio
  • 如何在 Blackberry BrowserField 中缓存

    我正在创建一个 Blackberry 应用程序来显示某个站点的全屏 Web 视图 我有一个可以正常显示的工作浏览器字段 但从页面到页面的导航速度比本机浏览器慢 浏览器字段似乎没有内置缓存 导致加载时间很慢 当我添加以下代码来管理缓存时 该站
  • FlipSide 上带有导航控制器和表格视图的实用应用程序

    我对整个 MVC 看待事物的方式还比较陌生 我有一个基于 实用程序 应用程序模板的应用程序 MainView 和 FlipsideView 中的所有内容都运行良好 但现在我需要将 TableView 和导航控制器添加到 Flipside 主
  • igraph错误无法创建具有负数顶点的空图

    当我尝试创建下面的简单图表时 为什么会出现错误 如果我用数字替换 a 和 b 那么它可以工作吗 任何解决方案 g1 lt graph c a b directed TRUE error is Error in graph c a b dir
  • 在 hibernate 聚合函数中使用函数作为参数

    我想在 HQL 中执行以下查询 select count distinct year foo date from Foo foo 但是 这会导致以下异常 org hibernate hql ast QuerySyntaxException
  • 如何在 Dynamics 365 On-Premise 中使用 EasyRepro 自动登录

    我正在尝试使用 Dynamics 365 On Premise 中的 EasyRepro 进行自动化 UI 测试 我成功完成了测试 但遇到了一个问题 我无法自动登录到我的 Dynamics 365 Organization 下面是我使用的代
  • 如何在VBA中进行后期绑定?

    我有一个通过 VBA 创建电子邮件的函数 我通过 Excel 2016 做到了这一点 当我的一些同事尝试使用它时 出现了缺少引用的错误 Outlook Library 16 0 我在互联网上寻找解决方案 发现最好的是后期绑定 我已经阅读过它
  • JButton 边距。当雨云普拉夫时不受尊重

    该物业margin of a JButton安装 Nimbus 外观后不会受到尊重 我需要一些 小 按钮 但 nimbus 强制按钮文本周围的空间变大 所以我只得到 非常大 的按钮 我发现在Nimbus 默认页面 http docs ora
  • 将 float 转换为 UInt32 - 哪个表达式更精确

    我有一个号码float x它应该在 范围内 但它经过多次数值运算 结果可能稍微超出 范围 我需要将这个结果转换为uint y使用整个范围的UInt32 当然 我需要夹住x在 范围内并对其进行缩放 但哪种操作顺序更好呢 y uint roun
  • 如何在netbeans中对ejs文件进行语法高亮显示

    我很长时间以来一直在 netbeans IDE 中工作 最近开始在 NodeJs 中编码 但 ejs 文件没有高亮代码 如何摆脱这个问题 您需要使用某些关联文件类型配置 ejs 文件扩展名 脚步 转到工具 gt 选项 单击 其他 选项卡 然
  • 如何在重新安装应用程序时删除数据

    感谢之前的回复 重新安装应用程序后是否可以从 sqlite 中删除存储的内容 我将数据存储在数据库中 一旦我再次重新安装相同的应用程序 以前的数据仍然存储在 sqlite 中 我想在重新安装应用程序时删除存储的内容 我对此不太确定 这看起来
  • 使用spaCy 3.0将数据从旧的Spacy v2格式转换为全新的Spacy v3格式

    我有变量trainData其具有以下简化格式 Paragraph A entities 15 26 DiseaseClass 443 449 DiseaseClass 483 496 DiseaseClass Paragraph B ent
  • 添加对 MEF 插件项目的引用时,为什么会出现警告图标?

    我希望通过直接引用插件项目并实例化插件类来测试插件的核心类 当我创建测试控制台应用程序项目并将项目引用添加到插件项目时 我在引用列表中的引用旁边看到一个警告图标 带有感叹号的黄色三角形 当我添加对 dll 插件的程序集构建输出 的引用时 我
  • AngularJS:拒绝设置不安全标头“Access-Control-Request-Headers”

    我正在尝试使用 AngularJS 调用本地运行的 REST API 这是 AngularJS 代码 http defaults headers common Access Control Request Headers accept or
  • 具有 n 倍交叉验证的精确召回曲线显示标准偏差

    我想生成一条具有 5 倍交叉验证的精确召回曲线 显示标准偏差 如ROC 曲线代码示例在这里 https scikit learn org stable auto examples model selection plot roc cross
  • 无法使用 ksoap2 在 Android 中序列化错误

    我有一个 magento soap v2 api 网络服务 我可以使用 ksoap2 从 android 进行通信 下面给出了我尝试过的 xml 和编码 XML API