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


Java JSONObject类代码示例

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


JSONObject类属于org.apache.wink.json4j包,在下文中一共展示了JSONObject类的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: parseJsonObjectIDList

import org.apache.wink.json4j.JSONObject; //导入依赖的package包/类
public static int[] parseJsonObjectIDList(JSONObject spec, String[] colnames, String group) 
	throws JSONException
{
	int[] colList = new int[0];
	boolean ids = spec.containsKey("ids") && spec.getBoolean("ids");
	
	if( spec.containsKey(group) && spec.get(group) instanceof JSONArray )
	{
		JSONArray colspecs = (JSONArray)spec.get(group);
		colList = new int[colspecs.size()];
		for(int j=0; j<colspecs.size(); j++) {
			JSONObject colspec = (JSONObject) colspecs.get(j);
			colList[j] = ids ? colspec.getInt("id") : 
				(ArrayUtils.indexOf(colnames, colspec.get("name")) + 1);
			if( colList[j] <= 0 ) {
				throw new RuntimeException("Specified column '" +
					colspec.get(ids?"id":"name")+"' does not exist.");
			}
		}
		
		//ensure ascending order of column IDs
		Arrays.sort(colList);
	}
	
	return colList;
}
 
开发者ID:apache,项目名称:systemml,代码行数:27,代码来源:TfMetaUtils.java

示例5: convertToFrame

import org.apache.wink.json4j.JSONObject; //导入依赖的package包/类
/**
 * Converts an input stream of a string frame in csv or textcell format
 * into a frame block. The meta data string is the SystemML generated
 * .mtd file including the number of rows and columns.
 * 
 * @param input InputStream to a string frame in csv or textcell format
 * @param meta string representing SystemML frame metadata in JSON format
 * @return frame as a frame block
 * @throws IOException if IOException occurs
 */
public FrameBlock convertToFrame(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 frame
		return convertToFrame(input, rows, cols, format);
	}
	catch(Exception ex) {
		throw new IOException(ex);
	}
}
 
开发者ID:apache,项目名称:systemml,代码行数:28,代码来源:Connection.java

示例6: loadMapData

import org.apache.wink.json4j.JSONObject; //导入依赖的package包/类
static public MapData loadMapData(String projectPath, JSONObject formatJSON){
	MapData mapData = null;
	JSONObject mapFormatJSON = null;
	try {
		mapFormatJSON = formatJSON.getJSONObject("map");
	} catch (JSONException e) {
		e.printStackTrace();
	}
	for(MapDataReader mapReader: mapReaderLoader){
		if(mapReader.hasReadMethod(mapFormatJSON)){
			System.out.println("MapDataReader="+mapReader);
			mapData = mapReader.read(projectPath, mapFormatJSON);
			return mapData;
		}
	}
	throw new RuntimeException("MapDataReader was not found. MapFormatJSON = "+mapFormatJSON);
}
 
开发者ID:hulop,项目名称:BLELocalization,代码行数:18,代码来源:ObservationModelBuilder.java

示例7: loadTestData

import org.apache.wink.json4j.JSONObject; //导入依赖的package包/类
public TestData loadTestData(String projectPath, JSONObject formatJSON, MapData mapData, String group){
	String testDataDir = projectPath + TestDataReaderBase.TEST_PATH;
	List<String> resNames = resReader.getResourceNames(testDataDir);
	String readMethod = toReadMethod(formatJSON);
	TestData testData = new TestData();
	if(DataUtils.hasReadMethod(readMethod)){
		for(String str: resNames){
			if(str.endsWith(CSV_EXT)){
				InputStream is = resReader.getInputStream(str);
				String[] strs = str.split("/");
				String fileName = strs[strs.length-1];
				List<Sample> samples = DataUtils.readCSVWalkingSamples(is, group);
				DataUnit data = new DataUnit(fileName, samples);
				testData.add(data);
				System.out.println(fileName + " is read by " + readMethod);
			}
		}
	}
	return testData;
}
 
开发者ID:hulop,项目名称:BLELocalization,代码行数:21,代码来源:TestDataReaderBase.java

示例8: movingAverageTestData

import org.apache.wink.json4j.JSONObject; //导入依赖的package包/类
public TestData movingAverageTestData(TestData testData, JSONObject formatJSON) {
	try {
		if (formatJSON.getJSONObject("test").has("movingAverageWindow")) {
			int mawindow = formatJSON.getJSONObject("test").getInt("movingAverageWindow");
			int nTest = testData.getSize();
			System.out.println("Test data moving averaged (window" + mawindow + ")");
			for (int i = 0; i < nTest; i++) {
				DataUnit tst = testData.get(i);
				List<Sample> smps = Sample.movingAverage(tst.getSamples(), mawindow);
				tst.setSamples(smps);
			}
		}
	} catch (JSONException e) {
		e.printStackTrace();
	}
	return testData;
}
 
开发者ID:hulop,项目名称:BLELocalization,代码行数:18,代码来源:TestDataReaderBase.java

示例9: BLEBeaconToJSONObject

import org.apache.wink.json4j.JSONObject; //导入依赖的package包/类
public static JSONObject BLEBeaconToJSONObject(BLEBeacon BLEBeacon){

		JSONObject jobj = new JSONObject();
		try{
			jobj.put("type","beacon");

			jobj.put("x", BLEBeacon.getX());
			jobj.put("y", BLEBeacon.getY());
			jobj.put("f", BLEBeacon.getZ());

			jobj.put("id", BLEBeacon.getMinor());
			jobj.put("major", BLEBeacon.getMajor());
			jobj.put("minor", BLEBeacon.getMinor());
			jobj.put("msdPower", BLEBeacon.getMsdPower());
			jobj.put("outPower", BLEBeacon.getOutputPower());
		}catch(JSONException e){
			e.printStackTrace();
		}
		return jobj;
	}
 
开发者ID:hulop,项目名称:BLELocalization,代码行数:21,代码来源:DataUtils.java

示例10: readStringFrame

import org.apache.wink.json4j.JSONObject; //导入依赖的package包/类
/**
 * Reads an input frame in arbitrary format from HDFS into a dense string array.
 * NOTE: this call currently only supports default configurations for CSV.
 * 
 * @param fname the filename of the input frame
 * @return frame as a two-dimensional string array
 * @throws IOException if IOException occurs
 */
public String[][] readStringFrame(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);
		String format = jmtd.getString(DataExpression.FORMAT_TYPE);
		InputInfo iinfo = InputInfo.stringExternalToInputInfo(format);
	
		//read frame file
		return readStringFrame(fname, iinfo, rows, cols);
	}
	catch(Exception ex) {
		throw new IOException(ex);
	}
}
 
开发者ID:apache,项目名称:systemml,代码行数:30,代码来源:Connection.java

示例11: toJSON

import org.apache.wink.json4j.JSONObject; //导入依赖的package包/类
public JSONObject toJSON(){
	JSONObject json = new JSONObject();

	JSONObject LDPLJSON = new JSONObject();
	JSONObject GPJSON = new JSONObject();
	JSONObject optJSON = new JSONObject();

	try {
		double[] params = getParams();
		LDPLJSON.put("n", params[0]).put("A", params[1]).put("fa", params[2]).put("fb", params[3]).put(HDIFF, hDiff);

		GPJSON.put("lengthes", new Double[]{lengthes[0], lengthes[1], lengthes[2]});
		GPJSON.put("sigmaP", stdev).put("sigmaN", sigmaN).put("useMask", gpLDPL.getUseMask()?1:0).put("constVar", gpLDPL.getOptConstVar());

		optJSON.put("optimizeHyperParameters", doHyperParameterOptimize?1:0);

		json.put(LDPLParameters, LDPLJSON);
		json.put(GPParameters, GPJSON);
		json.put(OPTIONS, optJSON);

	} catch (JSONException e) {
		e.printStackTrace();
	}

	return json;
}
 
开发者ID:hulop,项目名称:BLELocalization,代码行数:27,代码来源:GaussianProcessLDPLMeanModel.java

示例12: DataManagerImpl

import org.apache.wink.json4j.JSONObject; //导入依赖的package包/类
public DataManagerImpl(JSONObject settings) {
	this.settings = settings;
	if (this.settings == null) {
		return;
	}
	try {
		JSONArray array = settings.getJSONArray("configurations");
		if (array == null) {
			return;
		}
		for (int i = 0; i < array.length(); i++) {
			JSONObject config = array.getJSONObject(i);
			uuidSiteMap.put(config.getString("uuid"), config.getString("site_id"));
		}
	} catch (JSONException e) {
		e.printStackTrace();
	}
}
 
开发者ID:hulop,项目名称:BLELocalization,代码行数:19,代码来源:DataManagerImpl.java

示例13: 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

示例14: parseBinningColIDs

import org.apache.wink.json4j.JSONObject; //导入依赖的package包/类
public static List<Integer> parseBinningColIDs(JSONObject jSpec, String[] colnames) 
	throws IOException 
{
	try {
		if( jSpec.containsKey(TfUtils.TXMETHOD_BIN) && jSpec.get(TfUtils.TXMETHOD_BIN) instanceof JSONArray ) {
			return Arrays.asList(ArrayUtils.toObject(
					TfMetaUtils.parseJsonObjectIDList(jSpec, colnames, TfUtils.TXMETHOD_BIN)));	
		}
		else { //internally generates
			return Arrays.asList(ArrayUtils.toObject(
					TfMetaUtils.parseJsonIDList(jSpec, colnames, TfUtils.TXMETHOD_BIN)));	
		}
	}
	catch(JSONException ex) {
		throw new IOException(ex);
	}
}
 
开发者ID:apache,项目名称:systemml,代码行数:18,代码来源:TfMetaUtils.java

示例15: create

import org.apache.wink.json4j.JSONObject; //导入依赖的package包/类
public static  SyntheticDataGenerator create(JSONObject json){

		SyntheticDataGenerator gen = new SyntheticDataGenerator();

		try{
			JSONObject beaconJSON = json.getJSONObject("Beacon");
			JSONObject motionJSON = json.getJSONObject("Motion");

			gen.beaconGen = new SyntheticBeaconDataGenerator(beaconJSON);
			gen.motionGen = new SyntheticMotionDataGenerator(motionJSON);

			JSONObject randomJSON = json.getJSONObject("Random");
			int seed =  randomJSON==null ? 1234 : randomJSON.getInt("seed");
			gen.beaconGen.setRandom(new Random(seed));
			gen.motionGen.setRandom(new Random(seed));

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


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