1

次の文字列があります。

String Action="CreateUser"; String company="会社名";

しかし、上記の文字列を以下のjson文字列と同じように変換し、この文字列をサーバーに渡す方法

{"action":"CreateUser","user":{"company":{"solutionname":"","createdon":"","companyguid":"","nextinvoicenumber":"1000","companystatus":"Active","companyname":"","solutioncode":"InvoiceASAP"},"createdon":"","userstatus":"Active","companyguid":"","addressguid":"","guid":"","firstname":"Renuka","lastname":"Shah","email":"ren40@vprex.com","username":"","password":"renuka","cellphone":"","homephone":"","officephone":"","officeextension":"","faxnumber":"","phoneid":"1","sourceid":"1","primarycontact":"Y","permissioncode":"COMPANYADMIN","address":{"addr1":"","addr2":"","addr3":"","addr4":"","addr5":"","city":"","state":"","postalcode":"","country":"","note":""}}}

どんな助けでも大歓迎です。

4

2 に答える 2

1

次のようにします: http://snipplr.com/view/53225/

String Action="CreateUser"; String company="company name";
try
    {
        JSONObject action=new JSONObject();
        JSONObject user=new JSONObject();
        action.put("action", Action);
        action.put("user", user);

        JSONObject company=new JSONObject();
        user.put("company", company);
        user.put("userstatus", "Active");

        company.put("solutionname", "");
        company.put("nextinvoicenumber", "1000");
        //.... 
    }
    catch (Exception je)
    {

    }

JSONObject次に、 ( action) をサーバーに渡します。

于 2012-07-19T11:41:19.140 に答える
0

名前と値のペアの形式で値を JSONObject に入れます。

このような:

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();
    }
于 2012-07-19T11:40:51.210 に答える