public <T> T toObject(Class<T> clazz) { if (getFirstSourceText() == null) { return null; } return JSON.parseObject(getFirstSourceText(), clazz); }
@Override public Selectable jsonPath(String jsonPath) { JsonPathSelector jsonPathSelector = new JsonPathSelector(jsonPath); return selectList(jsonPathSelector,getSourceTexts()); } }
/** * remove padding for JSONP * @param padding padding * @return json after padding removed */ public Json removePadding(String padding) { String text = getFirstSourceText(); XTokenQueue tokenQueue = new XTokenQueue(text); tokenQueue.consumeWhitespace(); tokenQueue.consume(padding); tokenQueue.consumeWhitespace(); String chompBalanced = tokenQueue.chompBalancedNotInQuotes('(', ')'); return new Json(chompBalanced); }
/** * get json content of page * * @return json * @since 0.5.0 */ public Json getJson() { if (json == null) { json = new Json(rawText); } return json; }
public void process(Page page) { Json json = page.getJson(); //System.out.println(json); page.putField(ZhihuPipeline.URL, page.getUrl()); page.putField(ZhihuPipeline.RESPONSE, json); String isEnd = json.jsonPath("$.paging.is_end").get(); if (!Boolean.parseBoolean(isEnd)) { page.addTargetRequest(json.jsonPath("$.paging.next").get()); } List<String> urlTokens = json.jsonPath("$.data[*].url_token").all(); List<String> urls = generateFolloweeUrls(urlTokens); page.addTargetRequests(urls); }
/** * remove padding for JSONP * @param padding padding * @return json after padding removed */ public Json removePadding(String padding) { String text = getFirstSourceText(); XTokenQueue tokenQueue = new XTokenQueue(text); tokenQueue.consumeWhitespace(); tokenQueue.consume(padding); tokenQueue.consumeWhitespace(); String chompBalanced = tokenQueue.chompBalancedNotInQuotes('(', ')'); return new Json(chompBalanced); }
/** * get json content of page * * @return json * @since 0.5.0 */ public Json getJson() { if (json == null) { json = new Json(rawText); } return json; }
@Override public List<String> process(File inItem) { List<String> outItems = null; try { BufferedReader in = new BufferedReader( new FileReader(inItem) ); String s; in.readLine();//pass first line s = in.readLine(); if (s != null) { Json json = new Json(s); outItems = json.jsonPath("$.data[*].[*]").all(); } in.close(); } catch (IOException e) { e.printStackTrace(); } return outItems; } }
@Override public Selectable jsonPath(String jsonPath) { JsonPathSelector jsonPathSelector = new JsonPathSelector(jsonPath); return selectList(jsonPathSelector,getSourceTexts()); } }
public <T> List<T> toList(Class<T> clazz) { if (getFirstSourceText() == null) { return null; } return JSON.parseArray(getFirstSourceText(), clazz); }
@Override public List<Document> process(File inItem) { String s = readMember(inItem); List<Document> documents = null; if (!StringUtils.isEmpty(s)) { documents = new ArrayList<>(1); Json json = new Json(s); String id = json.jsonPath("$.id").get(); if (!duplicateRemover.isDuplicate(id)) { documents.add(new Document(id, s)); } } return documents; }
public <T> T toObject(Class<T> clazz) { if (getFirstSourceText() == null) { return null; } return JSON.parseObject(getFirstSourceText(), clazz); }
@Override public List<Document> process(File inItem) { String s = MemberURLTokenGenerator.readFollowees(inItem); List<Document> documents = null; if (!StringUtils.isEmpty(s)) { documents = new ArrayList<>(20); Json json = new Json(s); List<String> users = json.jsonPath("$.data[*].[*]").all(); List<String> ids = json.jsonPath("$.data[*].id").all(); int i = 0; for (String id : ids) { if (!duplicateRemover.isDuplicate(id)) { documents.add(new Document(id, users.get(i))); } i++; } } return documents; }
public <T> List<T> toList(Class<T> clazz) { if (getFirstSourceText() == null) { return null; } return JSON.parseArray(getFirstSourceText(), clazz); }