私は以下のようなJSONデータを持っている::HttpPostリクエストを使用する前にJSONObjectにデータを追加する方法は?
workidsパラメータの{
"lastName":"sadfsdf",
"email":"[email protected]",
"gender":"male",
"workids":[0,0],
"roleId":102
}
私はのparamsのArrayListのを使用。
{
List<Integer> ll = new ArrayList<Integer>();
ll.add(100);
ll.add(102);
}
私はこの
{
JSONObject json = new JSONObject();
json.put("lastName", "bbdddb");
json.put("email","[email protected]");
json.put("gender","male");
json.put("secGameIds",ll);
json.put("roleId",secGame);
}
これは私が作ったポストリクエストだったようにJSONオブジェクトにのparamsを追加しました。
{
HttpPost post = new HttpPost(uri);
post.setHeader("Content-type", "application/json");
post.setEntity(new StringEntity(json.toString(), "UTF-8"));
DefaultHttpClient client = new DefaultHttpClient();
HttpResponse httpresponse = client.execute(post);
}
私が原因の代わりに整数のリストの文字列として送信し、このパラメータjson.toString()
にこのプログラム{json.put("secGameIds",ll);}
を実行してみてください。 要求を行うときにのみ、そのパラメータを整数リストとしてどのようにすることができますか?
ありがとうございました&よろしく。
おそらくJSONArrayを使用して代わりにJsonObject –
へのArrayListを追加する必要があります使用そして、 "Integer Listの代わりにStringとして送信する" json.toString()を明確にすることはできますか? "もちろん、それは整数リストではなくJSONオブジェクトを明示的にtoString-dという文字列として送信します –