如何使用改造后方法发送json对象?[关闭]

How to send json object using retrofit post method? [closed]

提问人:forex developer 提问时间:11/15/2023 更新时间:11/15/2023 访问量:26

问:


想改进这个问题吗?通过编辑这篇文章添加详细信息并澄清问题。

1小时前关闭。

公共接口 APIInterface { 字符串 BASE_URL = “http://dev.myforexeye.com/mfe-live/apis/api/”;

@Headers({
        "Accept: application/json",
        "Content-Type: application/json"
})

@POST("get_latest_post")
Call<JSONObject> get_latest_post(@Body JSONObject latestPost);

}

{ "type" : "get_latest_post" }, "version_no" : "1.1.28" }

public interface APIInterface { String BASE_URL = "http://dev.myforexeye.com/mfe-live/apis/api/"; @Headers({ "Accept: application/json", "Content-Type: application/json" }) @POST("get_latest_post") Call<JSONObject> get_latest_post(@Body JSONObject latestPost); } 'public void getLatestPosts() { JSONObject postParam = new JSONObject(); try { JSONObject parm2 = new JSONObject(); parm2.put(“type”, “get_latest_post”); postParam.put(“request”, parm2); postParam.put(“version_no”, BuildConfig.VERSION_NAME); // new WebserviceMainController(new GetLatestPost(), getActivity(), false, postParam);Log.d(“android json”, postParam.toString());} catch (异常 e) { } 调用 call = APIClient.getClient().create(APIInterface.class).get_latest_post(postParam);调用 call = jsonPostService.postRawJSON(jsonObject);call.enqueue(new Callback() { @Override public void onResponse(调用调用,响应 jsonObject) { try { Log.d(“android json”, jsonObject.toString()); if (jsonObject.body().getString(“statusCode”).equals(“200”)) { typeList.clear();Gson gson = 新 Gson();DashLatestPostModel dashLatestPostModel = gson.fromJson(jsonObject.toString(), DashLatestPostModel.class);if (dashLatestPostModel != null) { try { ArrayList<DashLatestPostModel.Post> List = (ArrayList<DashLatestPostModel.Post>) dashLatestPostModel.getPost(); typeList.addAll(列表);字符串 postbanner_host_url = dashLatestPostModel.getUrl();getblogstype(typeList, postbanner_host_url);} catch (异常 e) { e.printStackTrace();else { Toast.makeText(getActivity(), dashLatestPostModel.getMessage(), Toast.LENGTH_SHORT).show();else { Toast.makeText(getActivity(), jsonObject.body().getString(“message”), Toast.LENGTH_SHORT).show();catch (异常 e) { e.printStackTrace();@Override public void onFailure(Call jsonObject, Throwable t) { Toast.makeText(getActivity(), jsonObject.toString(), Toast.LENGTH_SHORT).show(); // Log.e(“response-failure”, call.toString());}

java android json 改造

评论


答: 暂无答案