Android Asynchronous Http Client 如何使用Post请求提交Json数据?
public void mydemo() {
RequestParams params = new RequestParams();
/**
-
{
"id": 6, "title": "", "code": "", "linenos": false, "language": "python", "style": "friendly" } */ params.put("title", ""); params.put("code", ""); params.put("linenos", false); params.put("language", "python"); params.put("style", "friendly"); DjangoRestClient.post("/demo/snippets/", params, new JsonHttpResponseHandler() { @Override public void onSuccess(int statusCode, Header[] headers, JSONObject response) { // If the response is JSONObject instead of expected JSONArray try { System.out.println(response); } catch (Exception e) { e.printStackTrace(); } } @Override public void onSuccess(int statusCode, Header[] headers, JSONArray timeline) { try { System.out.println(statusCode); } catch (Exception e) { e.printStackTrace(); } } });
}
提交Json数据:不就是提交json字符串。你只要把要提交的json数据转换成字符串,然后放到RequestParams里面去不就行了。