本文整理汇总了Java中org.json.simple.parser.ParseException.printStackTrace方法的典型用法代码示例。如果您正苦于以下问题:Java ParseException.printStackTrace方法的具体用法?Java ParseException.printStackTrace怎么用?Java ParseException.printStackTrace使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.json.simple.parser.ParseException
的用法示例。
在下文中一共展示了ParseException.printStackTrace方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: handleWeatherMessage
import org.json.simple.parser.ParseException; //导入方法依赖的package包/类
/**
* handleWeatherMessage takes received telemetry message and processes it to be printed to command line.
* @param msg Telemetry message received through hono server.
*/
private void handleWeatherMessage(final Message msg) {
final Section body = msg.getBody();
//Ensures that message is Data (type of AMQP messaging). Otherwise exits method.
if (!(body instanceof Data))
return;
//Gets deviceID.
final String deviceID = MessageHelper.getDeviceId(msg);
//Creates JSON parser to read input telemetry weather data. Prints data to console output.
JSONParser parser = new JSONParser();
try {
Object obj = parser.parse(((Data) msg.getBody()).getValue().toString());
JSONObject payload = (JSONObject) obj;
System.out.println(new StringBuilder("Device: ").append(deviceID).append("; Location: ").
append(payload.get("location")).append("; Temperature:").append(payload.get("temperature")));
} catch (ParseException e) {
System.out.println("Data was not sent in a readable way. Check telemetry input.");
e.printStackTrace();
}
}
示例2: mergeFiles
import org.json.simple.parser.ParseException; //导入方法依赖的package包/类
/**
* merge source file into target
*
* @param target
* @param source
*/
public void mergeFiles(File target, File source) throws Throwable {
String targetReport = FileUtils.readFileToString(target);
String sourceReport = FileUtils.readFileToString(source);
JSONParser jp = new JSONParser();
try {
JSONArray parsedTargetJSON = (JSONArray) jp.parse(targetReport);
JSONArray parsedSourceJSON = (JSONArray) jp.parse(sourceReport);
// Merge two JSON reports
parsedTargetJSON.addAll(parsedSourceJSON);
// this is a new writer that adds JSON indentation.
Writer writer = new JSONWriter();
// convert our parsedJSON to a pretty form
parsedTargetJSON.writeJSONString(writer);
// and save the pretty version to disk
FileUtils.writeStringToFile(target, writer.toString());
} catch (ParseException pe) {
pe.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
}
示例3: createStartingCollection
import org.json.simple.parser.ParseException; //导入方法依赖的package包/类
private JSONObject createStartingCollection() {
try {
JSONObject collection = new JSONObject();
for (String card: JSonReader.getCollection()) {
Card c = new Card(card);
if (!c.getType().equals("hero")) {
if (c.getSet().equals("BASIC")) {
collection.put(card, 2);
} else {
collection.put(card, 0);
}
}
}
return collection;
} catch (ParseException e1) {
e1.printStackTrace();
}
return null;
}
示例4: validateSession
import org.json.simple.parser.ParseException; //导入方法依赖的package包/类
public JSONObject validateSession(String sessionid) {
String cSession = getSession(sessionid);
if (cSession == null) {
return null;
}
try{
Date now = new Date();
JSONObject sessionJson = (JSONObject) new JSONParser().parse(cSession);
String timeoutString = sessionJson.get("timeoutTime").toString();
JSONObject timeJson = (JSONObject) new JSONParser().parse(timeoutString);
if (now.getTime() > (Long)timeJson.get("$date")) {
removeSession(cSession);
return null;
}
return sessionJson;
}catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return null;
}
}
示例5: getWeather
import org.json.simple.parser.ParseException; //导入方法依赖的package包/类
public double getWeather(boolean inCelsius){
double temperature=0;
String url = URL;
if(inCelsius) url += "&units=metric";
else url += "&units=imperial";
doLogging("Request came for getWeather", "INFO");
String response = fetchWeather(url);
System.out.println(response);
JSONParser parser = new JSONParser();
try {
JSONObject jo=(JSONObject)parser.parse(response);
// maintain cache of this JSONObject
temperature = Double.parseDouble((((JSONObject)jo.get("main")).get("temp")).toString());
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return temperature;
}
示例6: getKarma
import org.json.simple.parser.ParseException; //导入方法依赖的package包/类
/**
* Gets your karma
* @return The requestResponse of type JodelRequestResponse
*/
public JodelRequestResponse getKarma() {
JodelRequestResponse requestResponse = new JodelRequestResponse();
this.updateHTTPParameter();
JodelHTTPResponse karmaResponse = this.httpAction.getKarma();
requestResponse.httpResponseCode = karmaResponse.responseCode;
if (requestResponse.httpResponseCode == 200) {
String responseKarma = karmaResponse.responseMessage;
requestResponse.rawResponseMessage = responseKarma;
JSONParser parserCaptcha = new JSONParser();
try {
JSONObject responseCaptchaJson = (JSONObject) parserCaptcha.parse(responseKarma);
String karma = responseCaptchaJson.get("karma").toString();
requestResponse.responseValues.put("karma", karma);
} catch (ParseException e) {
requestResponse.rawErrorMessage = e.getMessage();
e.printStackTrace();
requestResponse.error = true;
requestResponse.errorMessage = "Could not parse response JSON!";
}
} else {
requestResponse.error = true;
}
return requestResponse;
}
示例7: getHumidity
import org.json.simple.parser.ParseException; //导入方法依赖的package包/类
public long getHumidity(){
long humidity=0;
String response = fetchWeather(URL);
JSONParser parser = new JSONParser();
doLogging("Request came for getHumidity", "INFO");
try {
JSONObject jo=(JSONObject)parser.parse(response);
//long speed = (long)((JSONObject)jo.get("wind")).get("speed");
humidity = (long)((JSONObject)jo.get("main")).get("humidity");
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
doLogging("Error in getHumidity "+e.getStackTrace(), "ERROR");
}
return humidity;
}
示例8: getEffect
import org.json.simple.parser.ParseException; //导入方法依赖的package包/类
public JSONObject getEffect() {
try {
return new org.json.JSONObject(reader.getEffect(name).toJSONString());
} catch (ParseException e) {
e.printStackTrace();
}
return new org.json.JSONObject();
}
示例9: renameFeatureIDsAndNames
import org.json.simple.parser.ParseException; //导入方法依赖的package包/类
/**
* Prepend parent directory name to all feature names for easier report analysis
*
* @param reportFile
*/
public void renameFeatureIDsAndNames(File reportFile) throws Throwable {
String reportDirName = reportFile.getParentFile().getName();
String fileAsString = FileUtils.readFileToString(reportFile);
JSONParser jp = new JSONParser();
try {
JSONArray parsedJSON = (JSONArray) jp.parse(fileAsString);
for (Object o : parsedJSON) {
JSONObject jo = (JSONObject) o;
String curFeatureID = jo.get("id").toString();
String curFeatureName = jo.get("name").toString();
String newFeatureID = String.format("%s - %s", reportDirName, curFeatureID);
String newFeatureName = String.format("%s - %s", reportDirName, curFeatureName);
log.info("Changing feature ID and Name from: " + curFeatureID + " / " + curFeatureName + " to: " + newFeatureID + " / " + newFeatureName);
jo.put("id", newFeatureID);
jo.put("name", newFeatureName);
}
// this is a new writer that adds JSON indentation.
Writer writer = new JSONWriter();
// convert our parsedJSON to a pretty form
parsedJSON.writeJSONString(writer);
// and save the pretty version to disk
FileUtils.writeStringToFile(reportFile, writer.toString());
} catch (ParseException pe) {
pe.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
}
示例10: heal
import org.json.simple.parser.ParseException; //导入方法依赖的package包/类
public void heal (int h) throws org.json.simple.parser.ParseException {
if (this.health < this.maxHealth && h != 0) {
HashMap<String, Object> arguments = new HashMap<>();
arguments.put("targetEntityType", "MINION");
try {
game.trigger("HealingTrigger", arguments);
} catch (ParseException e) {
e.printStackTrace();
}
}
this.health += h;
if (this.health > this.getMaxHealth()) {
this.health = this.getMaxHealth();
}
}
示例11: getBattleCry
import org.json.simple.parser.ParseException; //导入方法依赖的package包/类
public org.json.JSONObject getBattleCry() {
try {
return new org.json.JSONObject(reader.getBattlecry(name).toJSONString());
} catch (ParseException e) {
e.printStackTrace();
}
return new org.json.JSONObject();
}
示例12: getAura
import org.json.simple.parser.ParseException; //导入方法依赖的package包/类
public org.json.JSONObject getAura() {
try {
return new org.json.JSONObject(reader.getAura(name).toJSONString());
} catch (ParseException e) {
e.printStackTrace();
}
return new org.json.JSONObject();
}
示例13: heal
import org.json.simple.parser.ParseException; //导入方法依赖的package包/类
public void heal (int value){
if (this.health < this.maxHealth && value != 0) {
HashMap<String, Object> arguments = new HashMap<>();
arguments.put("targetEntityType", "HERO");
try {
game.trigger("HealingTrigger", arguments);
} catch (ParseException e) {
e.printStackTrace();
}
}
this.health += value;
if (this.health > this.maxHealth) {
this.health = this.maxHealth;
}
}
示例14: execute
import org.json.simple.parser.ParseException; //导入方法依赖的package包/类
private String execute(String tweetLine) {
ReadTwitterJSON readJson = null;
try {
readJson = new ReadTwitterJSON(tweetLine);
} catch (ParseException e) {
e.printStackTrace();
}
System.out.println(" Before ----->" + readJson.getTweet());
readJson.removeUrl();
System.out.println(" After ----->" + readJson.getTweet());
return readJson.getTweet();
}
示例15: doAuthentication
import org.json.simple.parser.ParseException; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
JSONObject doAuthentication(JSONObject svcReq, String reqId){
JSONObject reply = null;
JSONObject authReq = new JSONObject();
communicateWithMQ mqHandler = new communicateWithMQ();
mqHandler.connectToBroker();
String replyMq = mqHandler.createMq("svcQueueServiceGatewayAuthnReply");
authReq.put("svcName", "AuthenticationService");
authReq.put("funcName", "authenticateUser");
authReq.put("usrId", svcReq.get("usrId").toString());
authReq.put("reqId", reqId);
JSONArray params = new JSONArray();
JSONObject tmp = new JSONObject();
tmp.put("name", "param1"); //usrId
tmp.put("type", "String");
tmp.put("value", svcReq.get("usrId").toString());
params.add(tmp);
JSONObject tmp1 = new JSONObject();
tmp1.put("name", "param2"); //passwd
tmp1.put("type", "String");
tmp1.put("value", svcReq.get("passwd").toString());
params.add(tmp1);
authReq.put("params", params);
System.out.println(authReq);
mqHandler.send("svcQueueAuthenticationService", authReq, replyMq);
JSONParser parser = new JSONParser();
try {
String str = mqHandler.listenAndFilter().get("response").toString();
mqHandler.disconnect();
System.out.println("Response from Auth svc "+str);
reply = (JSONObject) parser.parse(str);
} catch (ParseException e) {
e.printStackTrace();
}
return reply;
}