I need to translate this HTTP POST request from JavaScript to Android.
I'm facing an issue with cids: []
. I am unable to create a JsonObject with the square brackets symbol [ ]
as it should be an empty array.
This is my original JavaScript code:
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);
}
});
};
And here's my corresponding Android code snippet:
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);