我是 Android 的新手。因此,我在使用 Json 数据的 Android 中努力处理 HttpPost。
JSONObject jsonObj = new JSONObject();
JSONObject jsonObjDasUser = new JSONObject();
jsonObj.put("name", "Login");
jsonObj.put("type", "request");
jsonObj.put("UserCredential", jsonObjUserCredential );
jsonObjUserCredential .put("username", id);
jsonObjUserCredential .put("password", password);
// Create the POST object and add the parameters
HttpPost httpPost = new HttpPost(url);
StringEntity entity = new StringEntity(jsonObj.toString(), HTTP.UTF_8);
entity.setContentType("application/json");
httpPost.setEntity(entity);
HttpClient client = new DefaultHttpClient();
我如何将 jsonObjUserCredential 作为一个实体包含起来,例如::
//StringEntity userCredential = new StringEntity(jsonObjUserCredential .toString(),HTTP.UTF_8);??????
这里做错了什么????
请帮帮我....
最佳答案
试试这个代码.. 希望这能解决你的问题..
JSONObject jsonObj = new JSONObject();
JSONObject jsonObjDasUser = new JSONObject();
jsonObj.put("name", "Login");
jsonObj.put("type", "request");
jsonObjUserCredential .put("username", id);
jsonObjUserCredential .put("password", password);
jsonObj.put("UserCredential", jsonObjUserCredential );
// Create the POST object and add the parameters
HttpPost httpPost = new HttpPost(url);
StringEntity entity = new StringEntity(jsonObj.toString(), HTTP.UTF_8);
关于android - 使用 JSON Body 执行 HTTPPost 请求,Android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13687928/