gpt4 book ai didi

javascript - Android http post 与参数

转载 作者:行者123 更新时间:2023-11-28 20:59:02 25 4
gpt4 key购买 nike

我必须将此 http 帖子从 JavaScript 转换为 Android。

我在使用 cids: [] 时遇到问题。我无法使用此符号 [ ] 创建 jsonobject。它应该是一个空数组。

这是我的 JavaScript:

var makeAjaxRequest = function () {
Ext.getBody().mask('Loading...', 'x-mask-loading', false);
var obj = {
uid: 1161,
cids: []
};
Ext.Ajax.request({
url: 'http://test.com.my',
method: 'POST',
params: { json: Ext.encode(obj) },
success: function (response, opts) {
Ext.getCmp('content').update(response.responseText);
Ext.getCmp('status').setTitle('Static test.json file loaded');
Ext.getBody().unmask();
var data = Ext.decode(response.responseText);
Ext.Msg.alert('result::', data.r[1].id, Ext.emptyFn);
}
});
};

这是我的 Android 代码:

    String[] temp = null; 
JSONObject json = new JSONObject();
HttpPost post = new HttpPost(url);
json.put("uid", 1161);
json.put("cids", temp);
List postParams = new ArrayList();
postParams.add(new BasicNameValuePair("json", json.toString()));
UrlEncodedFormEntity entity = new UrlEncodedFormEntity(postParams);
tv1.setText(postParams.toString());
post.setEntity(entity);
post.setHeader("Accept", "application/json");
response = client.execute(post);

最佳答案

使用String[] temp = null;是不正确的。

使用String[] temp = {};。这表示一个空数组。

关于javascript - Android http post 与参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11502358/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com