本文整理汇总了Java中net.sf.json.JSONObject.optString方法的典型用法代码示例。如果您正苦于以下问题:Java JSONObject.optString方法的具体用法?Java JSONObject.optString怎么用?Java JSONObject.optString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.sf.json.JSONObject
的用法示例。
在下文中一共展示了JSONObject.optString方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addGlobalConfigDataForSonarInstance
import net.sf.json.JSONObject; //导入方法依赖的package包/类
protected void addGlobalConfigDataForSonarInstance(JSONObject globalConfigData) {
String name = globalConfigData.optString("name");
int timeToWait = globalConfigData.optInt("timeToWait");
String url = globalConfigData.optString("url");
if (!"".equals(name)) {
GlobalConfigDataForSonarInstance globalConfigDataForSonarInstance;
String token = globalConfigData.optString("token");
if (StringUtils.isNotEmpty(token)) {
globalConfigDataForSonarInstance = new GlobalConfigDataForSonarInstance(name, url, globalConfigData.optString("token"), timeToWait);
} else {
globalConfigDataForSonarInstance = new GlobalConfigDataForSonarInstance(name, url, globalConfigData.optString("account"), Secret.fromString(Util.fixEmptyAndTrim(globalConfigData.optString("password"))), timeToWait);
}
if (!containsGlobalConfigWithName(name)) {
listOfGlobalConfigInstances.add(globalConfigDataForSonarInstance);
}
}
}
示例2: startOnline
import net.sf.json.JSONObject; //导入方法依赖的package包/类
public String startOnline() throws IOException {
String uri = address + "api/active/receiver/start";
LinkedList<FormBodyPart> partsList = new LinkedList<>();
partsList.add(new FormBodyPart("token", new StringBody(token)));
partsList.add(new FormBodyPart("projectKey", new StringBody(project)));
partsList.add(new FormBodyPart("title", new StringBody(title)));
JSONObject obj = queryObject(createPost(uri, partsList), 201);
return address + "gui/active/" + obj.optString("OnlineID", "N/A") + "/";
}
示例3: process
import net.sf.json.JSONObject; //导入方法依赖的package包/类
@Override
public boolean process(AGContext context, JSONObject env, JavaFileObject javaFileObject, TypeDefineCodeBlock typeDefineCodeBlock, Set<? extends BaseStatement> set) {
if (typeDefineCodeBlock.getAnnotation(IPCInvokeTaskManager.class.getSimpleName()) == null) {
Log.i(TAG, "the TypeDefineCodeBlock do not contains 'IPCInvokeTaskManager' annotation.(%s)", javaFileObject.getFileName());
return false;
}
if (set.isEmpty()) {
Log.i(TAG, "containsSpecialAnnotationStatements is nil");
return false;
}
final String outputDir = env.optString(EnvArgsConstants.KEY_OUTPUT_DIR);
final String pkg = env.optString(EnvArgsConstants.KEY_PACKAGE);
final String filePath = env.optString(EnvArgsConstants.KEY_FILE_PATH);
if (Util.isNullOrNil(outputDir)) {
Log.i(TAG, "process failed, outputDir is null or nil.(filePath : %s)", filePath);
return false;
}
JSONObject args = new JSONObject();
// args.put("template", "");
args.put("templateTag", "ipc-invoker-gentask");
args.put(ArgsConstants.EXTERNAL_ARGS_KEY_DEST_DIR, outputDir);
args.put("toFile", Util.joint(File.separator, Util.exchangeToPath(pkg),
String.format("%s$AG.java", typeDefineCodeBlock.getName().getName())));
args.put("fileObject", javaFileObject.toJSONObject());
args.put("methodSet", toJSONArray(set));
context.execProcess("template-processor", args);
return true;
}
示例4: process
import net.sf.json.JSONObject; //导入方法依赖的package包/类
@Override
public boolean process(AGContext context, JSONObject env, JavaFileObject javaFileObject, TypeDefineCodeBlock typeDefineCodeBlock, Set<? extends BaseStatement> set) {
if (typeDefineCodeBlock.getAnnotation(IPCInvokeTaskManager.class.getSimpleName()) == null) {
Log.i(TAG, "the TypeDefineCodeBlock do not contains 'IPCInvokeTaskManager' annotation.(%s)", javaFileObject.getFileName());
return false;
}
if (set.isEmpty()) {
Log.i(TAG, "containsSpecialAnnotationStatements is nil");
return false;
}
final String outputDir = env.optString(EnvArgsConstants.KEY_OUTPUT_DIR);
final String pkg = env.optString(EnvArgsConstants.KEY_PACKAGE);
final String filePath = env.optString(EnvArgsConstants.KEY_FILE_PATH);
if (Util.isNullOrNil(outputDir)) {
Log.i(TAG, "process failed, outputDir is null or nil.(filePath : %s)", filePath);
return false;
}
JavaFileObject fObject = new JavaFileObject();
fObject.addTypeDefineCodeBlock(createTypeDefineCodeBlock(typeDefineCodeBlock, set));
fObject.setPackageStatement(javaFileObject.getPackageStatement());
fObject.copyImports(javaFileObject);
fObject.attachEnvironmentArgs(javaFileObject.getEnvironmentArgs());
GenCodeTaskInfo taskInfo = new GenCodeTaskInfo();
taskInfo.FileName = fObject.getFileName();
taskInfo.RootDir = Util.joint(File.separator, outputDir, Util.exchangeToPath(pkg));
taskInfo.javaFileObject = fObject;
CustomizeGenerator generator = new CodeGenerator(fObject);
FileOperation.saveToFile(taskInfo, generator.genCode());
Log.i(TAG, "genCode rootDir : %s, fileName : %s, suffix : %s", taskInfo.RootDir, taskInfo.FileName, taskInfo.Suffix);
return true;
}