use of com.google.gson.JsonArray in project weixin-java-tools by chanjarster.
the class WxCpServiceImpl method userDelete.
@Override
public void userDelete(String[] userids) throws WxErrorException {
String url = "https://qyapi.weixin.qq.com/cgi-bin/user/batchdelete";
JsonObject jsonObject = new JsonObject();
JsonArray jsonArray = new JsonArray();
for (int i = 0; i < userids.length; i++) {
jsonArray.add(new JsonPrimitive(userids[i]));
}
jsonObject.add("useridlist", jsonArray);
post(url, jsonObject.toString());
}
use of com.google.gson.JsonArray in project weixin-java-tools by chanjarster.
the class WxCpServiceImpl method tagAddUsers.
@Override
public void tagAddUsers(String tagId, List<String> userIds, List<String> partyIds) throws WxErrorException {
String url = "https://qyapi.weixin.qq.com/cgi-bin/tag/addtagusers";
JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("tagid", tagId);
if (userIds != null) {
JsonArray jsonArray = new JsonArray();
for (String userId : userIds) {
jsonArray.add(new JsonPrimitive(userId));
}
jsonObject.add("userlist", jsonArray);
}
if (partyIds != null) {
JsonArray jsonArray = new JsonArray();
for (String userId : partyIds) {
jsonArray.add(new JsonPrimitive(userId));
}
jsonObject.add("partylist", jsonArray);
}
post(url, jsonObject.toString());
}
use of com.google.gson.JsonArray in project weixin-java-tools by chanjarster.
the class WxMenuGsonAdapter method deserialize.
public WxMenu deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
/*
* 操蛋的微信
* 创建菜单时是 { button : ... }
* 查询菜单时是 { menu : { button : ... } }
*/
WxMenu menu = new WxMenu();
JsonObject menuJson = json.getAsJsonObject().get("menu").getAsJsonObject();
JsonArray buttonsJson = menuJson.get("button").getAsJsonArray();
for (int i = 0; i < buttonsJson.size(); i++) {
JsonObject buttonJson = buttonsJson.get(i).getAsJsonObject();
WxMenu.WxMenuButton button = convertFromJson(buttonJson);
menu.getButtons().add(button);
if (buttonJson.get("sub_button") == null || buttonJson.get("sub_button").isJsonNull()) {
continue;
}
JsonArray sub_buttonsJson = buttonJson.get("sub_button").getAsJsonArray();
for (int j = 0; j < sub_buttonsJson.size(); j++) {
JsonObject sub_buttonJson = sub_buttonsJson.get(j).getAsJsonObject();
button.getSubButtons().add(convertFromJson(sub_buttonJson));
}
}
return menu;
}
use of com.google.gson.JsonArray in project weixin-java-tools by chanjarster.
the class WxMenuGsonAdapter method serialize.
public JsonElement serialize(WxMenu menu, Type typeOfSrc, JsonSerializationContext context) {
JsonObject json = new JsonObject();
JsonArray buttonArray = new JsonArray();
for (WxMenu.WxMenuButton button : menu.getButtons()) {
JsonObject buttonJson = convertToJson(button);
buttonArray.add(buttonJson);
}
json.add("button", buttonArray);
if (menu.getMatchRule() != null) {
Gson gson = new Gson();
json.add("matchrule", gson.toJsonTree(menu.getMatchRule()));
}
return json;
}
use of com.google.gson.JsonArray in project JsonPath by jayway.
the class GsonJsonProviderTest method list_of_numbers.
@Test
public void list_of_numbers() {
JsonArray objs = using(GSON_CONFIGURATION).parse(JSON_DOCUMENT).read("$.store.book[*].display-price");
assertThat(objs.iterator()).extracting("asDouble").containsExactly(8.95D, 12.99D, 8.99D, 22.99D);
}
Aggregations