|
本帖最后由 java 于 2017-8-10 19:15 编辑
- String jsonString = stringHttpResponse.getContent();
- ObjectMapper mapper = new ObjectMapper();
- try {
- JsonNode root = mapper.readTree(jsonString);
- Integer code = Integer.valueOf(root.get("code").asText());
- String msg = root.get("msg").asText();
- JsonNode dataAd = root.get("data");
- Integer adCount = Integer.valueOf(dataAd.get("adCount").asText());
- JsonNode adList = dataAd.get("adList");
- if (code == 0 && adCount == 1) {
- eventToast.setUrl(adList.get(0).get("url").asText());
- eventToast.setDeepLink(adList.get(0).get("deepLink").asText());
- eventToast.setText(adList.get(0).get("text").asText());
- eventToast.setTextLeft(adList.get(0).get("textLeft").asText());
- eventToast.setTextRight(adList.get(0).get("textRight").asText());
- eventToast.setActionId(Integer.valueOf(adList.get(0).get("actionId").asText()));
- JsonNode tkLoadUrlsNode = adList.get(0).get("tkLoadUrls");
- if (tkLoadUrlsNode.size() > 0) {
- String tkLoadUrl = tkLoadUrlsNode.get(0).asText();
- eventToast.getTkLoadUrls().add(tkLoadUrl);
- }
- JsonNode tkExposureUrlsNode = adList.get(0).get("tkExposureUrls");
- if (tkExposureUrlsNode.size() > 0) {
- String tkExposureUrl = tkExposureUrlsNode.get(0).asText();
- eventToast.getTkExposureUrls().add(tkExposureUrl);
- }
- JsonNode tkClickUrlsNode = adList.get(0).get("tkClickUrls");
- if (tkClickUrlsNode.size() > 0) {
- String tkClickUrl = tkClickUrlsNode.get(0).asText();
- eventToast.getTkClickUrls().add(tkClickUrl);
- }
- }
- } catch (IOException ex) {
- logger.error("VipPayServiceImpl handleAdResult: parse data failed, data = '{}', errorMsg = '{}'", stringHttpResponse.getContent(), ex.getMessage());
- }
复制代码 |
|