我需要在android中实现登录API。为此,我使用了RestClientHelper,这是Android https://github.com/ravi123shanker/SimpleRestClientHelper
中的第三方库但是我需要将json对象发送到网址,例如:
{
"id":1,
"username":"hello",
"password":"1223"
}
从他们的文档中,我可以为postParams赋予价值,例如:
{login=[{"id":1,"password":"hello","username":"1223"}]}
但是我需要像以上格式一样发送!我该怎么做:
我的功能是:
JSONArray productsJson = new JSONArray();
try {
JSONObject eachProduct = new JSONObject();
eachProduct.put("fcmid", fcm_id);
eachProduct.put("password", pin);
eachProduct.put("username", username);
productsJson.put(eachProduct);
}
catch (Exception e){
Log.e("Exception", "error");
}
ArrayMap<String, Object> postParams=new ArrayMap<>();
postParams.put("login", productsJson.toString());
Log.e("postParams","data "+postParams.toString());
RestClientHelper.getInstance().post(Constants.BASE_URL_USER_LOGIN , postParams, new RestClientHelper.RestClientListener() {
@Override
public void onSuccess(String response) {
}
@Override
public void onError(String error) {
}
});
请帮忙吗?
答案 0 :(得分:0)
似乎您需要将JsonObject插入JsonArray,然后将其绑定到登录参数
JSONArray jArray = new JSONArray();
jArray.put(productsJson);
...
postParams.put("login", jArray.toString());