如何使用Volley

时间:2018-02-02 00:10:34

标签: android json android-volley

我必须使用Volley在服务器上发布三个参数。

1)appointment_id

2)visit_medicines

3)药物(json药物,例如[1,2,4])

这是我的代码

  Map<String, String> params = new HashMap<String, String>();
  params.put("appointment_id", "" + appointment_id);
  params.put("visit_notes", "sdssdsd");
  params.put("medicines", "1");
  getInstance().HttpPOSTRequestWithParameters(getApplicationContext(), ADD_PRESCRIPTION_API, params,AddPriscriptions.this);

通过上面的代码发布了除药品之外的所有内容(空的医疗数组从服务器返回)。这意味着我以错误的方式发布到服务器。

我很困惑如何发布JSON数组,因为我必须将[1,2,4]发布到服务器。该建议将不胜感激。

1 个答案:

答案 0 :(得分:1)

由于hashmap的receive类型是<String, String>,尝试将JSON数组转换为字符串,然后将其放入params hashmap

像这样

params.put("medicines", "[1,2,4]");