Java Code Examples for net.sf.json.JSONArray#get()
The following examples show how to use
net.sf.json.JSONArray#get() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Config.java From pdf-extract with GNU General Public License v3.0 | 6 votes |
private List<NormalizeInfo> getNormalizeList(JSONArray jArray) { List<NormalizeInfo> list = new ArrayList<>(); if (jArray != null) { for (int j = 0, jlen = jArray.size(); j < jlen; j++) { JSONArray jNormalize = (JSONArray) jArray.get(j); String left = jNormalize.getString(0); String right = jNormalize.getString(1); if (!common.IsEmpty(left) && right.length() > 0) { NormalizeInfo norm = new NormalizeInfo(); norm.search = left; norm.replace = right; list.add(norm); } } } return list; }
Example 2
Source File: Config.java From pdf-extract with GNU General Public License v3.0 | 6 votes |
private List<JoinWordInfo> getJoinWordsList(JSONArray jArray) { List<JoinWordInfo> list = new ArrayList<>(); if (jArray != null) { for (int j = 0, jlen = jArray.size(); j < jlen; j++) { JSONArray jNormalize = (JSONArray) jArray.get(j); String front = jNormalize.getString(0); String back = jNormalize.getString(1); String replace = jNormalize.getString(2); JoinWordInfo joinw = new JoinWordInfo(); joinw.front = front; joinw.back = back; joinw.joinText = replace; list.add(joinw); } } return list; }
Example 3
Source File: Config.java From pdf-extract with GNU General Public License v3.0 | 6 votes |
private List<EOFInfo> getEOFList(JSONArray jArray) { List<EOFInfo> list = new ArrayList<>(); if (jArray != null) { for (int j = 0, jlen = jArray.size(); j < jlen; j++) { JSONArray jEOF = (JSONArray) jArray.get(j); String front = jEOF.getString(0); String back = jEOF.getString(1); EOFInfo eofi = new EOFInfo(); eofi.front = front; eofi.back = back; list.add(eofi); } } return list; }
Example 4
Source File: ConceptMappingController.java From Criteria2Query with Apache License 2.0 | 6 votes |
@RequestMapping("/linkConceptSet") @ResponseBody public Map<String, Object> translateToJSON(HttpSession httpSession, String conceptsets){ JSONArray ja=JSONArray.fromObject(conceptsets); Map<String,Integer> conceptset_manual=new HashMap<String,Integer>(); for(int i=0;i<ja.size();i++){ JSONObject jo=(JSONObject) ja.get(i); System.out.println(jo.get("entity")); conceptset_manual.put((String) jo.get("entity"), (Integer)jo.get("conceptsetid")); } Document doc = (Document) httpSession.getAttribute("allcriteria"); doc = this.conceptMappingService.linkConceptSetsToTerms(doc, conceptset_manual); httpSession.setAttribute("allcriteria",doc); Map<String,Object> map=new HashMap<String,Object>(); return map; }
Example 5
Source File: ConceptMappingServiceImpl.java From Criteria2Query with Apache License 2.0 | 5 votes |
public Set<Integer> getAllConceptIds(Integer conceptSetId) { JSONObject set1=OHDSIApis.querybyconceptSetid(conceptSetId); Set<Integer> conceptIds=new HashSet<Integer>(); JSONObject jo=(JSONObject) set1.get("expression"); JSONArray ja=(JSONArray) jo.get("items"); if(ja.size()>0){ for(int i=0;i<ja.size();i++){ JSONObject conceptunit=(JSONObject) ja.get(i); JSONObject concept=(JSONObject) conceptunit.get("concept"); conceptIds.add(concept.getInt("CONCEPT_ID")); } } return conceptIds; }
Example 6
Source File: ModelConverterUtils.java From cloudbreak with Apache License 2.0 | 5 votes |
private static List<Object> toList(JSONArray array) throws JSONException { List<Object> list = new ArrayList<>(); for (int i = 0; i < array.size(); i++) { Object value = array.get(i); if (value instanceof JSONArray) { value = toList((JSONArray) value); } else if (value instanceof JSONObject) { value = toMap((JSONObject) value); } list.add(value); } return list; }
Example 7
Source File: WeixinTagController.java From jeewx-boot with Apache License 2.0 | 4 votes |
/** * @功能:同步标签 * @param response * @param request * @return */ @RequestMapping(value="syncTags",method = {RequestMethod.GET,RequestMethod.POST}) @ResponseBody public AjaxJson syncTags(HttpServletResponse response,HttpServletRequest request){ AjaxJson j = new AjaxJson(); //update-begin--Author:zhangweijian Date: 20180903 for:提示信息优化 JSONObject jsonObj=null; try { //获取accessToken String jwid=request.getSession().getAttribute("jwid").toString(); String accessToken=WeiXinHttpUtil.getRedisWeixinToken(jwid); //调用获取公众号标签接口 String requestUrl=get_tag_url.replace("ACCESS_TOKEN", accessToken); jsonObj=WeixinUtil.httpRequest(requestUrl,"GET",""); JSONArray Obj=(JSONArray) jsonObj.get("tags"); //将获取公众号已创建的标签插入标签表 if(Obj.size()>0){ //根据jwid清空该公众号创建的标签 weixinTagService.deleteTagsByJwid(jwid); for(int i=0;i<Obj.size();i++){ JSONObject tag=(JSONObject)Obj.get(i); WeixinTag weixinTag=new WeixinTag(); weixinTag.setJwid(jwid); weixinTag.setTagid(tag.getString("id")); weixinTag.setName(tag.getString("name")); weixinTag.setAddtime(new Date()); weixinTag.setSynctime(new Date()); weixinTagService.doAdd(weixinTag); j.setMsg("标签同步成功"); j.setSuccess(true); } } } catch (Exception e) { log.error(e.getMessage()); String errcode=jsonObj.getString("errcode"); j.setSuccess(false); j.setMsg("标签同步失败!错误码:<a target='_blank' href='https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1433747234'>"+errcode+"</a>"); } //update-end--Author:zhangweijian Date: 20180903 for:提示信息优化 return j; }
Example 8
Source File: RemoteService.java From BotLibre with Eclipse Public License 1.0 | 4 votes |
/** * Invoke the Pannous service. */ public String requestPannous(String message, String botid, String server, String apikey, int limit) throws Exception { try { if (server != null && !server.isEmpty()) { server = server.toLowerCase(); if (!server.startsWith("http")) { server = "http://" + server; } } else { server = PANNOUS; } String url = server + "/api?input=" + Utils.encodeURL(message); log("PANNOUS", Level.INFO, url); InputStream stream = Utils.openStream(Utils.safeURL(url)); String result = Utils.loadTextFile(stream, "UTF-8", 1000000); log("Response", Level.INFO, result); JSONObject json = (JSONObject)JSONSerializer.toJSON(result); if (json == null || json.isNullObject()) { return null; } JSONArray outputs = json.getJSONArray("output"); if (outputs == null || outputs.isEmpty()) { return null; } JSONObject output = (JSONObject)outputs.get(0); if (output == null || output.isNullObject()) { return null; } JSONObject actions = output.getJSONObject("actions"); if (actions == null || actions.isNullObject()) { return null; } JSONObject value = actions.getJSONObject("say"); if (value == null || value.isNullObject()) { return null; } String text = value.getString("text"); if (text == null) { return null; } if (limit > 0) { StringWriter writer = new StringWriter(); TextStream textStream = new TextStream(text); for (int index = 0; index < limit; index++) { if (textStream.atEnd()) { break; } writer.write(textStream.nextSentence()); } text = writer.toString(); } return text; } catch (Exception exception) { log(exception); return null; } }
Example 9
Source File: FreeBaseLinker.java From xcurator with Apache License 2.0 | 4 votes |
@Override public Set<String> findTypesForResource(String str, StringMetric metric, double threshold) { LogUtils.info(this.getClass(), "str=" + str); Set<String> types = new HashSet<String>(); String query = str.replaceAll("\\s", "+").replaceAll("%", "").replaceAll("\"", ""); final JSONArray json = FreebaseUtil.search(query, "resources/freebase/type_query.json", 5); if (json == null) { return null; } // Iterate through all elements in the array whose key name is "result" for (int i = 0; i < json.size(); i++) { // Get the element JSONObject resultElement = (JSONObject) json.get(i); // The boolean value to check if a element with name // similar to the provided text value has been found boolean same = false; // Get the "name" of the element String name = ""; try { name = resultElement.getString("name"); } catch (Exception e) { } // Check if the name and the provided text value is similar if (metric.getSimilarity(str, name) >= threshold) { same = true; } // If the name of the element is not similar, try to find // if a similar alias exists else { JSONArray aliases = resultElement.getJSONArray("/common/topic/alias"); for (int j = 0; j < aliases.size(); j++) { String alias = aliases.getString(j); if (metric.getSimilarity(str, alias) >= threshold) { same = true; break; } } } // If the current element has a name or an alias that is similar // to the provided text value if (same) { // Find the array of types of the element JSONArray typeArray = resultElement.getJSONArray("type"); // Iterate through each type for (int j = 0; j < typeArray.size(); j++) { // For each type, get its typeID, which looks something like "/music/release" String typeId = (((JSONObject) typeArray.get(j)).getString("id")); // Add the prefix to the typeID, which now looks something like // "http://rdf.freebase.com/rdf/music.release" typeId = freebaseTypePrefix + typeId.substring(1).replaceAll("/", "."); // Skip the current iteration if the typeID ends with "topic" if (typeId.endsWith("topic")) { continue; } // Add the typeID to types types.add(typeId); } } } return types; }
Example 10
Source File: FreeBaseLinker.java From xcurator with Apache License 2.0 | 4 votes |
@Override public Set<String> findSameAsForResource(String str, StringMetric metric, double threshold, Set<String> types2) { Set<String> ret = new HashSet<String>(); String query = str.replaceAll("\\s", "+").replaceAll("%", "").replaceAll("\"", ""); final JSONArray json = FreebaseUtil.search(query, "resources/freebase/type_query.json", 5); for (int i = 0; i < json.size(); i++) { JSONObject resultElement = (JSONObject) json.get(i); boolean same = false; String name = ""; try { name = resultElement.getString("name"); } catch (Exception e) { } if (metric.getSimilarity(str, name) >= threshold) { same = true; } else { JSONArray aliases = resultElement.getJSONArray("alias"); for (int j = 0; j < aliases.size(); j++) { String alias = aliases.getString(j); if (metric.getSimilarity(str, alias) >= threshold) { same = true; break; } } } if (same) { boolean typeMatches = false; JSONArray typeArray = resultElement.getJSONArray("type"); for (int j = 0; j < typeArray.size(); j++) { String typeId = ((JSONObject) typeArray.get(j)).getString("id"); typeId = freebaseTypePrefix + typeId.substring(1).replaceAll("/", "."); if (typeId.endsWith("topic")) { continue; } if (types2.contains(typeId)) { typeMatches = true; break; } } if (typeMatches) { ret.add(freebaseTypePrefix + resultElement.getString("id").substring(1).replace('/', '.')); } } } return ret; }