0

この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);
4

2 に答える 2

2

使用String[] temp = null;は正しくありません。

を使用しString[] temp = {};ます。これは、空の配列を示します。

于 2012-07-16T10:25:36.710 に答える
1

この記号「[]」でjsonobjectを作成することはできません。

^^これは基本的に、作成しようとしているJSON配列です。JSONObjectsには{}があり、JSONArraysには[]があります。

    public void writeJSON() {
    JSONObject user = new JSONObject();
    JSONObject user2;
    user2 = new JSONObject();
    try {
        user.put("dish_id", "1");
        user.put("dish_custom", "2");
        user.put("quantity", "2");
        user.put("shared", "2");

        user2.put("dish_id", "2");
        user2.put("dish_custom", "2");
        user2.put("quantity", "4");
        user2.put("shared", "3");
    } catch (JSONException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    JSONArray notebookUsers = new JSONArray();
    notebookUsers.put(user);
    notebookUsers.put(user2);
    System.out.println("the JSON ARRAY is"+notebookUsers);

記号「[]」を使用してuserとuser2のJSON配列を提供します

于 2012-07-16T10:26:27.057 に答える