Java Code Examples for net.sf.json.JSONArray#getString()

The following examples show how to use net.sf.json.JSONArray#getString() . 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 vote down vote up
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 vote down vote up
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 vote down vote up
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: NewsExtendBean.java    From wangmarket with Apache License 2.0 6 votes vote down vote up
/**
 * 通过 key 来获取 value 数据
 * @param key ,如 title、titlepic 
 * @return <ul>
 * 				<li>如果photojson 为null,则返回 "" 空字符串</li>
 * 				<li>如果取的key在photojson中不存在,则返回 "" 空字符串</li>
 * 				<li>如果取的key在photojson中存在,则返回具体的value字符串</li>
 * 			</ul>
 */
public String getExtendJson(String key) {
	if(extendJson == null){
		return "";
	}
	if(extendJson.get(key) == null){
		return "";
	}
	
	JSONArray jsonArray = extendJson.getJSONArray(key);
	if(jsonArray.size() == 1){
		//如果里面只有一个值,那么就将具体值返回
		return jsonArray.getString(0);
	}else{
		//如果里面有多个值,那么返回的将是数组
		return jsonArray.toString();
	}
}
 
Example 5
Source File: NewsDataBean.java    From wangmarket with Apache License 2.0 6 votes vote down vote up
/**
 * 通过 key 来获取 value 数据
 * @param key ,如 title、titlepic 
 * @return <ul>
 * 				<li>如果photojson 为null,则返回 "" 空字符串</li>
 * 				<li>如果取的key在photojson中不存在,则返回 "" 空字符串</li>
 * 				<li>如果取的key在photojson中存在,则返回具体的value字符串</li>
 * 			</ul>
 */
public String getExtendJson(String key) {
	if(extendJson == null){
		return "";
	}
	if(extendJson.get(key) == null){
		return "";
	}
	
	JSONArray jsonArray = extendJson.getJSONArray(key);
	if(jsonArray.size() == 1){
		//如果里面只有一个值,那么就将具体值返回
		return jsonArray.getString(0);
	}else{
		//如果里面有多个值,那么返回的将是数组
		return jsonArray.toString();
	}
}
 
Example 6
Source File: JwUserAPI.java    From jeewx-api with Apache License 2.0 5 votes vote down vote up
/**
 * 获取所有关注用户信息信息
 * 
 * @return
 * @throws WexinReqException 
 */
public static List<Wxuser> getAllWxuser(String accesstoken,String next_openid) throws WexinReqException {
	if (accesstoken != null) {
		UserInfoListGet userInfoListGet = new UserInfoListGet();
		userInfoListGet.setAccess_token(accesstoken);
		userInfoListGet.setNext_openid(next_openid);
		JSONObject result = WeiXinReqService.getInstance().doWeinxinReqJson(userInfoListGet);
		Object error = result.get("errcode");
		List<Wxuser> lstUser = null;
		Wxuser mxuser = null;
		int total = result.getInt("total");
		int count = result.getInt("count");
		String strNextOpenId = result.getString("next_openid");
		JSONObject data = result.getJSONObject("data");
		lstUser = new ArrayList<Wxuser>(total);
		if (count > 0) {
			JSONArray lstOpenid = data.getJSONArray("openid");
			int iSize = lstOpenid.size();
			for (int i = 0; i < iSize; i++) {
				String openId = lstOpenid.getString(i);
				mxuser = getWxuser(accesstoken, openId);
				lstUser.add(mxuser);
			}
			if (strNextOpenId != null) {
				lstUser.addAll(getAllWxuser(accesstoken, strNextOpenId));
			}
		}
		return lstUser;
	}
	return null;
}
 
Example 7
Source File: File.java    From xunxian with Apache License 2.0 5 votes vote down vote up
/**
	 * 自动扫货八卦灵石类加载数据
	 * <li>加载stone.xnx3文件,若是加载中数据出错,则自动使用默认数据data.Stone.stoneBak
	 */
	public void saoHuoStoneLoad(){
		Lang lang=new Func.Lang();
		try {
			String xnx3_content=new include.Module.TextFile().read(include.Command.thisFilePath+"\\config\\stone.xnx3", "UTF-8");
			xnx3_content=include.Module.UrlTransition.urlToUtf8(xnx3_content);
			JSONArray j=JSONArray.fromObject(xnx3_content);
			List l=j.toList(j);
//			List l=new Stone().stoneBak();
			SaoHuoFunc saoHuoFunc=new SaoHuoFunc();
			Command.JframeSaoHuo.stonejTable.removeAll();	//移除所有的重新添加
			DefaultTableModel tableModel=(DefaultTableModel) Command.JframeSaoHuo.stonejTable.getModel();
			Command.saoHuoStone.clear();		//情空,重新放入
			tableModel.getDataVector().clear();		//清空所有
			new Func.File().log("八卦灵石载入:"+l.size()+"条数据");
			for (int i = l.size()-1; i >-1; i--) {
				JSONArray jSub=JSONArray.fromObject(l.get(i));
				List lSub=jSub.toList(jSub);
//				System.out.println(jSub.get(0)+"-->"+jSub.get(1));
				String key=jSub.getString(0);
				int value=lang.Integer_(jSub.getString(1), 2);
				Command.saoHuoStone.put(key, value);
				Vector rowData = new Vector();
				rowData.add(key);
				rowData.add(saoHuoFunc.moneyToString(value));
				rowData.add(value);
				tableModel.insertRow(0, rowData);
				rowData=null;
			}
			saoHuoFunc=null;
			new Func.File().log("加载自动扫货八卦灵石类数据完毕");
		} catch (Exception e) {
			e.printStackTrace();
			new Func.Message().showMessageDialog("初始化失败!<br/>加载自动扫货八卦灵石类数据异常<br/>八卦灵石类数据已自动还原为初始数据");
//			Command.saoHuoStone=new Stone().stoneBak();
			new Func.File().log("加载自动扫货八卦灵石类数据异常!");
		}
		lang=null;
	}
 
Example 8
Source File: ComProfileFieldDaoImpl.java    From openemm with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public ComProfileField mapRow(ResultSet resultSet, int row) throws SQLException {
	ComProfileField readProfileField = new ComProfileFieldImpl();

	readProfileField.setCompanyID(resultSet.getInt(FIELD_COMPANY_ID));
	readProfileField.setShortname(resultSet.getString(FIELD_SHORTNAME));
	readProfileField.setDescription(resultSet.getString(FIELD_DESCRIPTION));
	readProfileField.setColumn(resultSet.getString(FIELD_COLUMN_NAME));
	readProfileField.setDefaultValue(resultSet.getString(FIELD_DEFAULT_VALUE));
	readProfileField.setModeEdit(resultSet.getInt(FIELD_MODE_EDIT));
	readProfileField.setModeInsert(resultSet.getInt(FIELD_MODE_INSERT));
	readProfileField.setCreationDate(resultSet.getTimestamp(FIELD_CREATION_DATE));
	readProfileField.setChangeDate(resultSet.getTimestamp(FIELD_CHANGE_DATE));
	readProfileField.setHistorize(resultSet.getBoolean(FIELD_HISTORIZE));

	Object sortObject = resultSet.getObject(FIELD_SORT);
	if (sortObject != null) {
		readProfileField.setSort(((Number)sortObject).intValue());
	} else {
		readProfileField.setSort(MAX_SORT_INDEX);
	}

	Object lineObject = resultSet.getObject(FIELD_LINE);
	if (lineObject != null) {
		readProfileField.setLine(((Number)lineObject).intValue());
	} else {
		readProfileField.setLine(0);
	}

	Object interestObject = resultSet.getObject(FIELD_ISINTEREST);
	if (interestObject != null) {
		readProfileField.setInterest(((Number)interestObject).intValue());
	} else {
		readProfileField.setInterest(0);
	}

	String allowedValuesJson = resultSet.getString(FIELD_ALLOWED_VALUES);
	String[] allowedValues = null;
	if (allowedValuesJson != null) {
		try {
			JSONArray array = JSONArray.fromObject(allowedValuesJson);
			allowedValues = new String[array.size()];
			for (int i = 0; i < array.size(); i++) {
				allowedValues[i] = array.getString(i);
			}
		} catch (JSONException e) {
			logger.error("Error occurred while parsing JSON: " + e.getMessage(), e);
		}
	}
	readProfileField.setAllowedValues(allowedValues);

	return readProfileField;
}
 
Example 9
Source File: File.java    From xunxian with Apache License 2.0 4 votes vote down vote up
/**
	 * 自动扫货宠物壳子类加载数据
	 * <li>加载pet.xnx3文件,若是加载中数据出错,则自动使用默认数据data.Pet.petBak
	 */
	public void saoHuoPetLoad(){
		Lang lang=new Func.Lang();
		Command.saoHuoPet.clear();		//清空Map
		Command.saoHuoPet=new data.Pet().petBak();
		
		try {
			String xnx3_content=new include.Module.TextFile().read(include.Command.thisFilePath+"\\config\\pet.xnx3", "UTF-8");
			xnx3_content=include.Module.UrlTransition.urlToUtf8(xnx3_content);
			JSONArray j=JSONArray.fromObject(xnx3_content);
			List l=j.toList(j);
//			List l=new Pet().petBak();
			SaoHuoFunc saoHuoFunc=new SaoHuoFunc();
			Command.JframeSaoHuo.petjTable.removeAll();	//移除所有的重新添加
			DefaultTableModel tableModel=(DefaultTableModel) Command.JframeSaoHuo.petjTable.getModel();
			tableModel.getDataVector().clear();		//清空所有
			
			new Func.File().log("宠物壳子载入:"+l.size()+"条数据");
			for (int i = l.size()-1; i >-1; i--) {
				JSONArray jSub=JSONArray.fromObject(l.get(i));
				List lSub=jSub.toList(jSub);
				String key=jSub.getString(0);
				int value=lang.Integer_(jSub.getString(1), 2);
				System.out.println("Key->"+key+"-->"+value);
				Command.saoHuoPet.put(key, value);
			}
			
			Set<Map.Entry<String, Integer>> set = Command.saoHuoPet.entrySet();
	        for (Iterator<Map.Entry<String, Integer>> it = set.iterator(); it.hasNext();) {
	            Map.Entry<String, Integer> entry = (Map.Entry<String, Integer>) it.next();
	            Vector rowData = new Vector();
				rowData.add(entry.getKey());
				rowData.add(saoHuoFunc.moneyToString(entry.getValue()));
				rowData.add(entry.getValue());
				tableModel.insertRow(0, rowData);
				rowData=null;
	        }
			
			saoHuoFunc=null;
			new Func.File().log("加载自动扫货宠物壳子类数据完毕");
		} catch (Exception e) {
			e.printStackTrace();
			new Func.Message().showMessageDialog("初始化失败!<br/>加载自动扫货宠物壳子类数据异常<br/>宠物壳子类数据已自动还原为初始数据");
//			Command.saoHuoStone=new Stone().stoneBak();
			new Func.File().log("加载自动扫货宠物壳子类数据异常!");
		}
		lang=null;
	}
 
Example 10
Source File: File.java    From xunxian with Apache License 2.0 4 votes vote down vote up
/**
	 * 自动扫货风物志类加载数据
	 * <li>加载fengWuZhi.xnx3文件,若是加载中数据出错,则自动使用默认数据data.FengWuZhi()
	 */
	public void saoHuoFengWuZhiLoad(){
		Lang lang=new Func.Lang();
		Command.saoHuoFengWuZhi.clear();		//清空Map
		Command.saoHuoFengWuZhi=new data.FengWuZhi().fengWuZhiBak();
		
		try {
			String xnx3_content=new include.Module.TextFile().read(include.Command.thisFilePath+"\\config\\fengWuZhi.xnx3", "UTF-8");
			xnx3_content=include.Module.UrlTransition.urlToUtf8(xnx3_content);
			JSONArray j=JSONArray.fromObject(xnx3_content);
			List l=j.toList(j);
//			List l=new Pet().petBak();
			SaoHuoFunc saoHuoFunc=new SaoHuoFunc();
			Command.JframeSaoHuo.fengWuZhijTable.removeAll();	//移除所有的重新添加
			DefaultTableModel tableModel=(DefaultTableModel) Command.JframeSaoHuo.fengWuZhijTable.getModel();
			tableModel.getDataVector().clear();		//清空所有
			
			new Func.File().log("风物志载入:"+l.size()+"条数据");
			for (int i = l.size()-1; i >-1; i--) {
				JSONArray jSub=JSONArray.fromObject(l.get(i));
				List lSub=jSub.toList(jSub);
				String key=jSub.getString(0);
				int value=lang.Integer_(jSub.getString(1), 2);
				Command.saoHuoFengWuZhi.put(key, value);
			}
			
			Set<Map.Entry<String, Integer>> set = Command.saoHuoFengWuZhi.entrySet();
	        for (Iterator<Map.Entry<String, Integer>> it = set.iterator(); it.hasNext();) {
	            Map.Entry<String, Integer> entry = (Map.Entry<String, Integer>) it.next();
	            Vector rowData = new Vector();
				rowData.add(entry.getKey());
				rowData.add(saoHuoFunc.moneyToString(entry.getValue()));
				rowData.add(entry.getValue());
				tableModel.insertRow(0, rowData);
				rowData=null;
	        }
			
			saoHuoFunc=null;
			new Func.File().log("加载自动扫货风物志类数据完毕");
		} catch (Exception e) {
			e.printStackTrace();
		}
		lang=null;
	}
 
Example 11
Source File: File.java    From xunxian with Apache License 2.0 4 votes vote down vote up
/**
	 * 自动扫货传奇配方类加载数据
	 * <li>加载legend.xnx3文件,若是加载中数据出错,则自动使用默认数据data.Legend()
	 */
	public void saoHuoLegendLoad(){
		Lang lang=new Func.Lang();
		Command.saoHuoLegend.clear();		//清空Map
		Command.saoHuoLegend=new data.Legend().legendBak();
		
		try {
			String xnx3_content=new include.Module.TextFile().read(include.Command.thisFilePath+"\\config\\legend.xnx3", "UTF-8");
			xnx3_content=include.Module.UrlTransition.urlToUtf8(xnx3_content);
			JSONArray j=JSONArray.fromObject(xnx3_content);
			List l=j.toList(j);
//			List l=new Pet().petBak();
			SaoHuoFunc saoHuoFunc=new SaoHuoFunc();
			Command.JframeSaoHuo.legendjTable.removeAll();	//移除所有的重新添加
			DefaultTableModel tableModel=(DefaultTableModel) Command.JframeSaoHuo.legendjTable.getModel();
			tableModel.getDataVector().clear();		//清空所有
			
			new Func.File().log("传奇配方载入:"+l.size()+"条数据");
			for (int i = l.size()-1; i >-1; i--) {
				JSONArray jSub=JSONArray.fromObject(l.get(i));
				List lSub=jSub.toList(jSub);
				String key=jSub.getString(0);
				int value=lang.Integer_(jSub.getString(1), 2);
				Command.saoHuoLegend.put(key, value);
			}
			
			Set<Map.Entry<String, Integer>> set = Command.saoHuoLegend.entrySet();
	        for (Iterator<Map.Entry<String, Integer>> it = set.iterator(); it.hasNext();) {
	            Map.Entry<String, Integer> entry = (Map.Entry<String, Integer>) it.next();
	            Vector rowData = new Vector();
				rowData.add(entry.getKey());
				rowData.add(saoHuoFunc.moneyToString(entry.getValue()));
				rowData.add(entry.getValue());
				tableModel.insertRow(0, rowData);
				rowData=null;
	        }
			
			saoHuoFunc=null;
			new Func.File().log("加载自动扫货传奇配方类数据完毕");
		} catch (Exception e) {
			e.printStackTrace();
		}
		lang=null;
	}
 
Example 12
Source File: FreeBaseLinker.java    From xcurator with Apache License 2.0 4 votes vote down vote up
@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 13
Source File: FreeBaseLinker.java    From xcurator with Apache License 2.0 4 votes vote down vote up
@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;
}