如何发送JSON请求并从服务器获取JSON响应

时间:2019-04-23 17:50:42

标签: java android client android-volley

我有一台服务器,我需要向该服务器发送请求并获得响应。 我正在使用volley,这是我到目前为止所做的

JSONObject request=new JSONObject();
try {
    request.put("ticket_id", ticket_id);
    request.put("start", start);
    request.put("extra", extra);
    request.put("care_category", care_category);
    request.put("k_means", "10");
    request.put("vendor", vendor);
    request.put("earlier_enteries", earlier_enteries);
} catch (JSONException e) {
    e.printStackTrace();
}

响应类似于:

{"calculation":5.4444"}

我应该如何处理我的请求,或者是否有更好的方法?

1 个答案:

答案 0 :(得分:0)

您必须使用HTTPs请求(GET和POST)。 Retrofit和Gson将完成它。

有很多关于它的教程和示例。 参见Retrofit Android Example HTTP GET Request

相关问题