[英]Adding empty array to a JSON object
我正在尝试创建一个如下所示的JSON对象:
{"filters": {"defaultOperator":"OR", "filters":[]}}
我应该添加到我的JSON对象中以创建一个空数组对象?? 无法绕过一个空阵列。
试过jo1.put("filters",new Object[0]);
。 这没用。
我正在测试一个API,它只需要在特殊情况下填充这些数组,大部分时间都是空的。 但不知道如何添加它。 我正在创建条目JSON
JSONObject jo1 = new JSONObject();
jo1.put("defaultOperator", "OR");
jo1.put("filters","[]");
jo3 = new JSONObject();
jo3.put("filters", jo1);
//Toast.makeText(getApplicationContext(),""+jo3.toString() , Toast.LENGTH_LONG).show();
//json = new GsonBuilder().create().toJson(comment1, Map.class);
httppost.setEntity(new StringEntity(jo3.toString()));
JSONArray jarr = new JSONArray();
jo1.put("filters",jarr);
或全部在一条线上:
jo1.put("filters", new JSONArray());
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.