2016-08-08 42 views
-2

レスポンシブな配列を受け取るWebサービスを呼び出そうとしています。私はアンドロイドに改造を使用して値を持つハッシュマップを送信していますが、それは500内部サーバーerror.Followingが私のコードで私を与えている: @POST("/save") public void CreateAccount( @Body Map<String, String> data, Callback<Response> callback);retrofitを使用してアンドロイドからレスポンシブな配列を送信するには

+0

応答配列は何ですか? – Yazan

+0

応答配列は、キー値のペアで構成されます – vinit

+0

意味**連想配列**?そうであれば、キー値構造体を探しています。マップが動作していない場合は、JsonObjectのキーを埋めるようにして、 'jsonObj.toString()'をサーバに送ります。そうでなければリクエストを取得する必要がありますサーバーに送信されたときのようにデータが表示される – Yazan

答えて

0

あなたは改修2

インターフェイスでこれを行うことができます方法は次のとおりです。

@POST("/save") 
    Call<JsonElement> CreateAccount(@Body RequestBody requestBody); 

リクエストコード:

//create JsonObject with key-pair values 
JsonObject root = new JsonObject(); 
root.addProperty("key1", "value1"); 
root.addProperty("key2", "value2"); 
//get is as string 
String resultJson = root.toString(); 
//parse it to RequestBody type 
RequestBody requestBody = RequestBody.create(MediaType.parse("application/json"), resultJson); 
//create adapter 
Retrofit restAdapter = new Retrofit.Builder() 
     .baseUrl(Constants.ROOT_API_URL) 
     .addConverterFactory(GsonConverterFactory.create()) 
     .build(); 
IConstructSecureAPI service = restAdapter.create(IConstructSecureAPI.class); 

Call<JsonElement> result = service.CreateAccount(requestBody); 
result.enqueue(new Callback<JsonElement>() { 
    @Override 
    public void onResponse(Call<JsonElement> call, retrofit2.Response<JsonElement> response) { 
     if(response.isSuccessful()){ 
      JsonElement jsonElement = response.body(); 
      JsonObject withResponse = jsonElement.getAsJsonObject(); 
     } 
     else{ 
      System.out.println(response.message()); 
     } 
    } 

    @Override 
    public void onFailure(Call<JsonElement> call, Throwable t) { 

    } 
}); 
関連する問題