当前位置: 首页>>代码示例>>Java>>正文


Java JSONObject.getString方法代码示例

本文整理汇总了Java中org.apache.wink.json4j.JSONObject.getString方法的典型用法代码示例。如果您正苦于以下问题:Java JSONObject.getString方法的具体用法?Java JSONObject.getString怎么用?Java JSONObject.getString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.wink.json4j.JSONObject的用法示例。


在下文中一共展示了JSONObject.getString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: parseGroups

import org.apache.wink.json4j.JSONObject; //导入方法依赖的package包/类
/**
 * Main logic for parsing the groups from the JSON file. Also does validation of the groups attributes.
 * @param groups JSONArray object that contains the groups parsed from the JSON file.
 * @param groupType the type of the groups in the JSONArray Object.
 * @return An ArrayList of Group Objects that contain the parsed information.
 * @throws JSONException
 * @throws AdeUsageException
 */
private List<Group> parseGroups(JSONArray groups, String groupType) throws JSONException, AdeUsageException{
    if (groups.length() == 0) throw new AdeUsageException("No groups specified for group of type " + groupType);
    List<Group> currentGroups = new ArrayList<Group>();
    for (int i = 0; i < groups.length(); i++){
        JSONObject group = groups.getJSONObject(i);
        String name = group.getString("name");
        String dataType = group.getString("dataType");
        short evalOrder = group.getShort("evaluationOrder");
        String ruleName = group.getString("ruleName");
     
        if (!verifyStringParam(name, 200, "[a-zA-Z0-9_ ]*") || name.equalsIgnoreCase("unassigned")
                || !validateDataType(dataType) || evalOrder < 1 || !verifyStringParam(ruleName, 200, "[a-zA-Z0-9_ ]*")){
            throw new AdeUsageException("Invalid parameters for a group of type " + groupType + " was specified");
        }
        currentGroups.add(new Group(name, GroupType.valueOf(groupType), DataType.valueOf(dataType.toUpperCase()), evalOrder, ruleName));
    }
    
    validateEvaluationOrderAndName(currentGroups);
    
    return currentGroups;        
}
 
开发者ID:openmainframeproject,项目名称:ade,代码行数:30,代码来源:JSONGroupParser.java

示例2: parseRules

import org.apache.wink.json4j.JSONObject; //导入方法依赖的package包/类
/**
 * Main logic for parsing the rules from the JSON file. Also does validation of the rules attributes.
 * @param groups JSONArray object that contains the groups parsed from the JSON file.
 * @param rules JSONArray object that contains the rules parsed from the JSON file.
 * @return An ArrayList of Rule Objects that contain the parsed information.
 * @throws AdeUsageException
 * @throws JSONException
 */
private List<Rule> parseRules(JSONArray rules) throws AdeUsageException, JSONException{
    if (rules.length() == 0) throw new AdeUsageException("No rules specified");
    List<Rule> currentRules = new ArrayList<Rule>();
    for (int i = 0; i < rules.length(); i++){
        JSONObject rule = rules.getJSONObject(i);
        String name = rule.getString("name");
        String description = rule.getString("description");
        String membershipRule = rule.getString("membershipRule");
        
        if (!verifyStringParam(name, 200, "[a-zA-Z0-9_ ]*") || (description != null && description.length() > 1000)
                || name.equalsIgnoreCase("unassigned_rule") || !verifyStringParam(membershipRule,256,"[a-zA-Z0-9.:?/*-]*")){
            throw new AdeUsageException("Invalid parameters for rules was specified");
        }
        
        currentRules.add(new Rule(name, membershipRule, description));
        
        validateRuleNames(currentRules);
    }
    return currentRules;
}
 
开发者ID:openmainframeproject,项目名称:ade,代码行数:29,代码来源:JSONGroupParser.java

示例3: toResetLocalizationInput

import org.apache.wink.json4j.JSONObject; //导入方法依赖的package包/类
private LocalizationInput toResetLocalizationInput(JSONObject source) throws JSONException {
	String uuid = source.getString("uuid");
	LocalizationInput locInput = new LocalizationInput();
	locInput.setUuid(uuid).setUpdateMode(UpdateMode.reset);
	try{
		if(!source.isNull("xtrue") && !source.isNull("ytrue") && !source.isNull("ztrue")){
			double xtrue = source.getDouble("xtrue");
			double ytrue = source.getDouble("ytrue");
			double ztrue = source.getDouble("ztrue");
			locInput.setInitialLocation(xtrue, ytrue, ztrue);
		}
		if(!source.isNull("theta")){
			double theta = source.getDouble("theta");
			locInput.setInitialOrientation(theta);
		}
	} catch(JSONException e){
		e.printStackTrace();
	}
	return locInput;
}
 
开发者ID:hulop,项目名称:BLELocalization,代码行数:21,代码来源:BeaconLocalizer.java

示例4: toCorrectLocalizationInput

import org.apache.wink.json4j.JSONObject; //导入方法依赖的package包/类
private LocalizationInput toCorrectLocalizationInput(JSONObject source) throws JSONException {
	String uuid = source.getString("uuid");
	LocalizationInput locInput = new LocalizationInput();
	locInput.setUuid(uuid).setUpdateMode(UpdateMode.correct);
	try{
		double xtrue = source.getDouble("xtrue");
		double ytrue = source.getDouble("ytrue");
		double ztrue = source.getDouble("ztrue");
		locInput.setInitialLocation(xtrue, ytrue, ztrue);
		double xstdev = source.getDouble("stdevxy");
		double ystdev = xstdev;
		double zstdev = 0.0;
		locInput.setStdevLocTrue(xstdev, ystdev, zstdev);
	} catch(JSONException e){
		e.printStackTrace();
	}
	return locInput;
}
 
开发者ID:hulop,项目名称:BLELocalization,代码行数:19,代码来源:BeaconLocalizer.java

示例5: convertToMatrix

import org.apache.wink.json4j.JSONObject; //导入方法依赖的package包/类
/**
 * Converts an input stream of a string matrix in csv or textcell format
 * into a matrix block. The meta data string is the SystemML generated
 * .mtd file including the number of rows and columns.
 * 
 * @param input InputStream to a string matrix in csv or textcell format
 * @param meta string representing SystemML matrix metadata in JSON format
 * @return matrix as a matrix block
 * @throws IOException if IOException occurs
 */
public MatrixBlock convertToMatrix(InputStream input, String meta) 
	throws IOException
{
	try {
		//parse json meta data 
		JSONObject jmtd = new JSONObject(meta);
		int rows = jmtd.getInt(DataExpression.READROWPARAM);
		int cols = jmtd.getInt(DataExpression.READCOLPARAM);
		String format = jmtd.getString(DataExpression.FORMAT_TYPE);
		
		//parse the input matrix
		return convertToMatrix(input, rows, cols, format);
	}
	catch(Exception ex) {
		throw new IOException(ex);
	}
}
 
开发者ID:apache,项目名称:systemml,代码行数:28,代码来源:Connection.java

示例6: buildObservationModel

import org.apache.wink.json4j.JSONObject; //导入方法依赖的package包/类
public static ObservationModel buildObservationModel(JSONObject json, ProjectData projData){
	ObservationModel model=null;
	try {
		String name = json.getString("name");
		System.out.println("Building an observation model : "+name);

		for(ObservationModelFactory obsProv: obsLoader){
			System.out.println("ObservationModelProvider="+obsProv.getClass().getSimpleName());
			if(obsProv.hasModel(json)){
				System.out.println("ObservationModelProvider="+obsProv.getClass().getSimpleName() +" is creating an observation model.");
				model = obsProv.create(json, projData);
			}
		}

		if(model==null){
			System.err.println("Unknown observation model name: "+name);
			throw new RuntimeException();
		}
	} catch (JSONException e) {
		e.printStackTrace();
	}
	return model;
}
 
开发者ID:hulop,项目名称:BLELocalization,代码行数:24,代码来源:ModelBuilderCore.java

示例7: create

import org.apache.wink.json4j.JSONObject; //导入方法依赖的package包/类
public static BeaconFilter create(JSONObject json){
	BeaconFilter bf = null;
	try{
		String name = json.getString("name");
		JSONObject params = json.getJSONObject("parameters");
		for(BeaconFilter bfTemp: loader){
			if(name.equals(bfTemp.getClass().getSimpleName())){
				bf = bfTemp;
				bf.settingFromJSON(params);
				break;
			}
		}
		if(bf==null){
			System.err.println(name + " is not supported in "+BeaconFilterFactory.class.getSimpleName()+".");
		}
	}catch(JSONException e){
		e.printStackTrace();
	}
	return bf;
}
 
开发者ID:hulop,项目名称:BLELocalization,代码行数:21,代码来源:BeaconFilterFactory.java

示例8: instantiateModel

import org.apache.wink.json4j.JSONObject; //导入方法依赖的package包/类
private ObservationModel instantiateModel(JSONObject config, JSONObject options){
	System.out.println("Initializing a localization model.");

	// Parse configs
	String modelID = null, projectName = null, site_id = null;
	try {
		modelID = config.getString("model");
		projectName = config.getString("project");
		site_id = config.getString("site_id");
	} catch (JSONException e) {
		e.printStackTrace();
	}
	if (modelID == null || projectName == null || site_id == null) {
		System.err.println("model,  project, and site_id should be specified");
		System.err.println(config.toString());
		return null;
	}

	// Build an observation model.
	String projectPath = manager.getProjectsDir()+"/"+projectName;
	String modelPath = manager.getModelsDir()+"/"+modelID;

	ObservationModelBuilder builder = new ObservationModelBuilder();
	if(options!=null){
		builder.setEnvironmentOption(options);
	}
	builder.setProjectPathAndModelPath(projectPath, modelPath).printStatus();
	builder.setReadsTest(false).loadProject().loadModel();
	ObservationModel observationModel = builder.getObservationModel();

	// Set up post processor if necessary.
	PostProcessor postProc = PostProcessorProvider.create(builder, config, options);
	if(postProc!=null){
		postProcessMap.put(site_id, postProc);
	}

	return observationModel;
}
 
开发者ID:hulop,项目名称:BLELocalization,代码行数:39,代码来源:LocalizationServiceImpl.java

示例9: Info

import org.apache.wink.json4j.JSONObject; //导入方法依赖的package包/类
public Info(JSONObject info){
	try{
		String uuid = info.getString(UUID);
		String site_id = info.getString(SITE_ID);
		this.uuid(uuid);
		this.siteId(site_id);
	} catch(JSONException e){
		e.printStackTrace();
	}
}
 
开发者ID:hulop,项目名称:BLELocalization,代码行数:11,代码来源:ProjectData.java

示例10: parseJSONFloors

import org.apache.wink.json4j.JSONObject; //导入方法依赖的package包/类
public static Map<String, Integer> parseJSONFloors(JSONArray floorsArray){
	Map<String, Integer> map = new LinkedHashMap<String, Integer>();
	try {
		Iterator<JSONObject> iter = uncheckedCast(floorsArray.iterator());
		while(iter.hasNext()){
			JSONObject jobj = iter.next();
			String floor = jobj.getString("floor");
			Integer floor_num  = jobj.getInt("floor_num");
			map.put(floor, floor_num);
		}
	} catch (JSONException e) {
		e.printStackTrace();
	}
	return map;
}
 
开发者ID:hulop,项目名称:BLELocalization,代码行数:16,代码来源:MapDataUtils.java

示例11: create

import org.apache.wink.json4j.JSONObject; //导入方法依赖的package包/类
public static LikelihoodModel create(JSONObject json){
	LikelihoodModel likelihoodModel = null;
	try {
		if(json==null){
			likelihoodModel = new NormalDist();
		}
		else if(json!=null){
			String name = json.getString("name");
			JSONObject paramsJSON = json.getJSONObject("parameters");

			for(LikelihoodModel lmTemp: loader){
				if(name.equals(lmTemp.getClass().getSimpleName())){
					likelihoodModel = lmTemp;
					likelihoodModel.settingFromJSON(paramsJSON);
					System.out.println(likelihoodModel.toString() + " was created.");
					break;
				}
			}
			if(likelihoodModel==null){
				System.err.println(name+ " is not supported in " + LikelihoodModelFactory.class.getSimpleName() + ".");
			}
		}
	} catch (JSONException e) {
		e.printStackTrace();
	}
	return likelihoodModel;
}
 
开发者ID:hulop,项目名称:BLELocalization,代码行数:28,代码来源:LikelihoodModelFactory.java

示例12: settingFromJSON

import org.apache.wink.json4j.JSONObject; //导入方法依赖的package包/类
public void settingFromJSON(JSONObject json){
  	// Parse json
  	try {
	Integer np = json.getInt(N_PARTICLES);
	setNumParticles(np);
	if(json.containsKey(AVERAGING_TYPE)){
		averagingType = json.getString(AVERAGING_TYPE);
		System.out.println(AVERAGING_TYPE + " is set to " + averagingType);
	}
	usesWeighted = averagingType.equals(WEIGHTED_AVERAGE)? true : false;
	if(json.containsKey(RESAMPLING_METHOD)){
		String str = json.getString(RESAMPLING_METHOD);
		resamplingMethodName = str;
		System.out.println(RESAMPLING_METHOD + " is set to " + resamplingMethodName);
	}
	alphaWeaken = json.containsKey(ALPHA_WEAKEN) ? json.getDouble(ALPHA_WEAKEN) : 1.0;
	System.out.println(this.toString());
} catch (JSONException e) {
	e.printStackTrace();
}

  	// Set up particle preprocessor
  	JSONObject prepJSON = json.optJSONObject(ParticlePreprocessor.PARTICLE_PREPROCESSOR);
  	if(prepJSON!=null){
  		ParticlePreprocessorProvider provider = new ParticlePreprocessorProvider();
  		if(provider.hasFactory(prepJSON)){
  			particlePreprocessor = provider.provide(prepJSON, this);
  			System.out.println(particlePreprocessor.toString() + " is created.");
  		}
  	}else{
  		System.out.println("The key for ["+ParticlePreprocessor.PARTICLE_PREPROCESSOR+"] was not found.");
  	}

  }
 
开发者ID:hulop,项目名称:BLELocalization,代码行数:35,代码来源:ParticleFilter.java

示例13: hasModel

import org.apache.wink.json4j.JSONObject; //导入方法依赖的package包/类
@Override
public boolean hasModel(JSONObject json) {
	try {
		String name = json.getString("name");
		if(name.equals(ParticleFilter.class.getSimpleName())){
			return true;
		}else if(name.equals(ParticleFilterWithSensor.class.getSimpleName())){
			return true;
		}
	} catch (JSONException e) {
		e.printStackTrace();
	}
	return false;
}
 
开发者ID:hulop,项目名称:BLELocalization,代码行数:15,代码来源:ParticleFilterModelFactory.java

示例14: create

import org.apache.wink.json4j.JSONObject; //导入方法依赖的package包/类
@Override
public ObservationModel create(JSONObject json, ProjectData projData) {
	ObservationModel model=null;
	try{

		String name = json.getString("name");
		JSONObject paramsJSON = json.getJSONObject("parameters");

		JSONObject sysJSON = paramsJSON.getJSONObject(SystemModel.class.getSimpleName());
		SystemModel sysModel =ModelBuilderCore.buildSystemModel(sysJSON, projData);

		JSONObject obsJSON = paramsJSON.getJSONObject(ObservationModel.class.getSimpleName());
		ObservationModel obsModel = ModelBuilderCore.buildObservationModel(obsJSON, projData);

		ParticleFilter pf = null;
		if(name.equals(ParticleFilter.class.getSimpleName())){
			pf = new ParticleFilter(sysModel, obsModel);
		}else if(name.equals(ParticleFilterWithSensor.class.getSimpleName())){
			pf = new ParticleFilterWithSensor(sysModel, obsModel);
		}
		pf.settingFromJSON(paramsJSON);
		pf.train(projData.trainData().getSamples());
		model = pf;

	}catch(JSONException e){
		e.printStackTrace();
	}
	return model;
}
 
开发者ID:hulop,项目名称:BLELocalization,代码行数:30,代码来源:ParticleFilterModelFactory.java

示例15: readDoubleMatrix

import org.apache.wink.json4j.JSONObject; //导入方法依赖的package包/类
/**
 * Reads an input matrix in arbitrary format from HDFS into a dense double array.
 * NOTE: this call currently only supports default configurations for CSV.
 * 
 * @param fname the filename of the input matrix
 * @return matrix as a two-dimensional double array
 * @throws IOException if IOException occurs
 */
public double[][] readDoubleMatrix(String fname) 
	throws IOException
{
	try {
		//read json meta data 
		String fnamemtd = DataExpression.getMTDFileName(fname);
		JSONObject jmtd = new DataExpression().readMetadataFile(fnamemtd, false);
		
		//parse json meta data 
		long rows = jmtd.getLong(DataExpression.READROWPARAM);
		long cols = jmtd.getLong(DataExpression.READCOLPARAM);
		int brlen = jmtd.containsKey(DataExpression.ROWBLOCKCOUNTPARAM)?
				jmtd.getInt(DataExpression.ROWBLOCKCOUNTPARAM) : -1;
		int bclen = jmtd.containsKey(DataExpression.COLUMNBLOCKCOUNTPARAM)?
				jmtd.getInt(DataExpression.COLUMNBLOCKCOUNTPARAM) : -1;
		long nnz = jmtd.containsKey(DataExpression.READNUMNONZEROPARAM)?
				jmtd.getLong(DataExpression.READNUMNONZEROPARAM) : -1;
		String format = jmtd.getString(DataExpression.FORMAT_TYPE);
		InputInfo iinfo = InputInfo.stringExternalToInputInfo(format);			
	
		//read matrix file
		return readDoubleMatrix(fname, iinfo, rows, cols, brlen, bclen, nnz);
	}
	catch(Exception ex) {
		throw new IOException(ex);
	}
}
 
开发者ID:apache,项目名称:systemml,代码行数:36,代码来源:Connection.java


注:本文中的org.apache.wink.json4j.JSONObject.getString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。