3

この形式でネストされたパラメーターを持つjsonを渡すための正しいコードは何ですか

 {"method":"startSession",
"params": [ "email": "testmail@test.it", 
            "password": "1234", 
            "stayLogged": "1", 
            "idClient": "ANDROID"
           ]
}

RPCを受信するWebサービスのURLに??

Webサービスコードは

 @Webservice(paramNames = {"email", "password", "stayLogged", "idClient"},
public Response startSession(String email, String password, Boolean stayLogged, String idClient) throws Exception {
    boolean rC = stayLogged != null && stayLogged.booleanValue();
    UserService us = new UserService();
    User u = us.getUsersernamePassword(email, password);
    if (u == null || u.getActive() != null && !u.getActive().booleanValue()) {
        return ErrorResponse.getAccessDenied(id, logger);
    }
    InfoSession is = null;
    String newKey = null;
    while (newKey == null) {
        newKey = UserService.md5(Math.random() + " " + new Date().getTime());
        if (SessionManager.get(newKey) != null) {
            newKey = null;
        } else {
            is = new InfoSession(u, rC, newKey);
            if (idClient != null && idClient.toUpperCase().equals("ANDROID")) {
                is.setClient("ANDROID");
            }
            SessionManager.add(newKey, is);
        }
    }
    logger.log(Level.INFO, "New session started: " + newKey + " - User: " + u.getEmail());
    return new Response(new InfoSessionJson(newKey, is), null, id);
}
4

1 に答える 1

2

リクエストにバージョンインジケーターがないため、json-rpc1.0を使用していると仮定します。

まず、「id」が欠落しているので、それをリクエストに追加します。

今ここにあなたが試すことができる3つの異なることがあります。

1)名前と値のペアを設定する場合は、配列[]の代わりにオブジェクト{}を使用する必要があります。好き:

{"method":"startSession",
"params": { "email": "testmail@test.it", 
            "password": "1234", 
            "stayLogged": "1", 
            "idClient": "ANDROID"
           },
 "id":100
}

2)jsonデシリアライザーが配列構文[]を必要としている場合は、次のようにオブジェクト{}を[]でラップする必要があります。

{"method":"startSession",
"params": [{ "email": "testmail@test.it", 
            "password": "1234", 
            "stayLogged": "1", 
            "idClient": "ANDROID"
           }],
  "id":101
}

3)最後に、次のような配列で位置パラメータを使用することもできます。

{"method":"startSession",
"params": [ "testmail@test.it", 
            "1234", 
            "1", 
            "ANDROID"
           ],
   "id":102
}

お役に立てば幸いです。

于 2012-05-04T22:36:05.427 に答える