Search in sources :

Example 36 with JsonArray

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());
}
Also used : JsonArray(com.google.gson.JsonArray) JsonPrimitive(com.google.gson.JsonPrimitive) JsonObject(com.google.gson.JsonObject)

Example 37 with JsonArray

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());
}
Also used : JsonArray(com.google.gson.JsonArray) JsonPrimitive(com.google.gson.JsonPrimitive) JsonObject(com.google.gson.JsonObject)

Example 38 with JsonArray

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;
}
Also used : JsonArray(com.google.gson.JsonArray) WxMenu(me.chanjar.weixin.common.bean.WxMenu) JsonObject(com.google.gson.JsonObject)

Example 39 with JsonArray

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;
}
Also used : JsonArray(com.google.gson.JsonArray) WxMenu(me.chanjar.weixin.common.bean.WxMenu) JsonObject(com.google.gson.JsonObject) Gson(com.google.gson.Gson)

Example 40 with JsonArray

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);
}
Also used : JsonArray(com.google.gson.JsonArray) Test(org.junit.Test)

Aggregations

JsonArray (com.google.gson.JsonArray)424 JsonObject (com.google.gson.JsonObject)290 JsonElement (com.google.gson.JsonElement)167 JsonPrimitive (com.google.gson.JsonPrimitive)118 Test (org.testng.annotations.Test)59 JsonParser (com.google.gson.JsonParser)57 ArrayList (java.util.ArrayList)50 HashMap (java.util.HashMap)34 Map (java.util.Map)34 Gson (com.google.gson.Gson)22 IOException (java.io.IOException)17 Test (org.junit.Test)16 Type (java.lang.reflect.Type)12 List (java.util.List)11 Matchers.anyString (org.mockito.Matchers.anyString)10 TextView (android.widget.TextView)9 Point (android.graphics.Point)8 JsonParseException (com.google.gson.JsonParseException)7 GsonUtilities.jboolean (com.ibm.streamsx.topology.internal.gson.GsonUtilities.jboolean)7 KcaUtils.getStringFromException (com.antest1.kcanotify.KcaUtils.getStringFromException)6