我们可以使用的JSONObject类,这是可用javax.json-1.0.2.jar打造以上JSON格式,
JsonObject jo = Json.createObjectBuilder()
.add("data", 2376845)
.add("data2", 12545)
.add("array",Json.createArrayBuilder()
.add(Json.createObjectBuilder().add("data3", "2013-01-10").add("data4", 23532).build())
.add(Json.createObjectBuilder().add("data3", "2013-01-11").add("data4", 523526).build()))
.build();
建设JSON格式
AsyncHttpClient client=new AsyncHttpClient();
Request request = client.preparePost(your host URL).
setHeader("Content-Type","application/json").
setHeader("Content-Length", ""+jo.toString().length()).setHeader("Authorization","Basic fgfgfgfhfhtetet=").
setBody(jo.toString()).build();
ListenableFuture<Response> r = null;
//ListenableFuture<Integer> f= null;
try{
r = client.executeRequest(request);
System.out.println(r.get().getResponseBody());
}catch(IOException e){
} catch (InterruptedException e) {
e.printStackTrace();
} catch (ExecutionException e) {
e.printStackTrace();
}
,如果你所需要的基础之后认证你需要添加一个密钥,这是一个密钥组合的用户名:用base64编码的密码到标题,如果不留下 在这种情况下,我将它添加到标题
主要是这将工作对你
注:AsyncHttpClient,ListenableFuture类在异步HTTP客户端-1.7.5.jar可用
退房http://stackoverflow.com/questions/6218143/android- post-json-using-http –