如何在Volley中传递Object和String作为参数?

时间:2017-02-09 05:01:41

标签: android android-volley

我似乎无法弄清楚如何将字符串和对象作为参数传递给Volley。我的所有调用目前只使用字符串,但对于这种特殊情况,我必须将对象和字符串的混合传递给API。

        @Override
        protected Map<String, String> getParams() {
            Map<String, Object> params = new HashMap<>();
            JSONObject content = new JSONObject();

            try {
                content.put("original_msg","hello");
                content.put("new_msg","hi");

                params.put("session_id", sessionId);
                params.put("type", "reply");
                params.put("content", content); //the object
            } catch (JSONException e) {
                e.printStackTrace();
            }

            return params; //returning an error: Incompatible Types
        }

2 个答案:

答案 0 :(得分:2)

JSON也被视为一个字符串,所有对象都提供params.put("content", content.toString()); 方法,以便任何子类都可以创建该Object的字符串表示。

Map<String, String> params = new HashMap();

从那里您需要将其更改为Ext.define('Ext.ux.form.field.CKEditor', { extend: 'Ext.form.field.TextArea', alias: 'widget.ckeditor', constructor: function () { this.callParent(arguments); this.addEvents("instanceReady"); this.addEvents("blur"); }, initComponent: function () { this.callParent(arguments); this.on("afterrender", function () { Ext.apply(this.CKConfig, { height: this.getHeight(), width: this.getWidth() }); this.editor = CKEDITOR.replace(this.inputEl.id, this.CKConfig); this.editor.name = this.name; this.editor.on("instanceReady", function () { this.fireEvent("instanceReady", this, this.editor ); }, this); this.editor.on("blur", function (){ this.fireEvent("blur", this, this.editor ); }, this) }, this); }, onRender: function (ct, position) { if (!this.el) { this.defaultAutoCreate = { tag: 'textarea', autocomplete: 'off' }; } this.callParent(arguments) }, setValue: function (value) { this.callParent(arguments); if (this.editor) { this.editor.setData(value); } }, getValue: function () { if (this.editor) { console.log(this.editor.getData()); return this.editor.getData(); } else { return '' } }

答案 1 :(得分:-1)

protected Map<String, String>更改为protected Map<String, Object>