本文整理了Java中org.codehaus.jettison.json.JSONObject.optJSONObject()
方法的一些代码示例,展示了JSONObject.optJSONObject()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JSONObject.optJSONObject()
方法的具体详情如下:
包路径:org.codehaus.jettison.json.JSONObject
类名称:JSONObject
方法名:optJSONObject
[英]Get an optional JSONObject associated with a key. It returns null if there is no such key, or if its value is not a JSONObject.
[中]获取与键关联的可选JSONObject。如果没有这样的键,或者其值不是JSONObject,则返回null。
代码示例来源:origin: apache/phoenix
public Set<String> getSubmittedYarnApps() throws Exception {
String rmHost = PhoenixMRJobUtil.getActiveResourceManagerHost(conf, zkQuorum);
Map<String, String> urlParams = new HashMap<String, String>();
urlParams.put(YarnApplication.APP_STATES_ELEMENT, YarnApplication.state.NEW.toString()
+ "," + YarnApplication.state.ACCEPTED + "," + YarnApplication.state.SUBMITTED
+ "," + YarnApplication.state.RUNNING);
int rmPort = PhoenixMRJobUtil.getRMPort(conf);
String response = PhoenixMRJobUtil.getJobsInformationFromRM(rmHost, rmPort, urlParams);
LOG.debug("Already Submitted/Running Apps = " + response);
JSONObject jobsJson = new JSONObject(response);
JSONObject appsJson = jobsJson.optJSONObject(YarnApplication.APPS_ELEMENT);
Set<String> yarnApplicationSet = new HashSet<String>();
if (appsJson == null) {
return yarnApplicationSet;
}
JSONArray appJson = appsJson.optJSONArray(YarnApplication.APP_ELEMENT);
if (appJson == null) {
return yarnApplicationSet;
}
for (int i = 0; i < appJson.length(); i++) {
Gson gson = new GsonBuilder().create();
YarnApplication yarnApplication =
gson.fromJson(appJson.getJSONObject(i).toString(),
new TypeToken<YarnApplication>() {
}.getType());
yarnApplicationSet.add(yarnApplication.getName());
}
return yarnApplicationSet;
}
代码示例来源:origin: org.codehaus.jettison/jettison
public void writeNamespace(String prefix, String ns) throws XMLStreamException {
((Node) getNodes().peek()).setNamespace(prefix, ns);
try {
JSONObject nsObj = getCurrentNode().optJSONObject("@xmlns");
if (nsObj == null) {
nsObj = new JSONObject();
getCurrentNode().put("@xmlns", nsObj);
}
if (prefix.equals("")) {
prefix = "$";
}
nsObj.put(prefix, ns);
} catch (JSONException e) {
throw new XMLStreamException(e);
}
}
代码示例来源:origin: com.tinkerpop.rexster/rexster-core
/**
* Given a request object, return the fragment of JSON that deals with Rexster-reserved parameters.
* <p/>
* These parameters are the returnKeys, showTypes, and offset.
*
* @param requestObject the request object
* @return the JSON
*/
public static JSONObject getRexsterRequest(final JSONObject requestObject) {
return requestObject != null ? requestObject.optJSONObject(Tokens.REXSTER) : null;
}
代码示例来源:origin: com.atlassian.jira/jira-rest-java-client-core
@SuppressWarnings("unused")
@Nullable
public static JSONObject getOptionalJsonObject(final JSONObject jsonObject, final String attributeName) {
final JSONObject res = jsonObject.optJSONObject(attributeName);
if (res == JSONObject.NULL || res == null) {
return null;
}
return res;
}
代码示例来源:origin: com.atlassian.jira/jira-rest-java-client
@SuppressWarnings("unused")
@Nullable
public static JSONObject getOptionalJsonObject(JSONObject jsonObject, String attributeName) {
final JSONObject res = jsonObject.optJSONObject(attributeName);
if (res == JSONObject.NULL || res == null) {
return null;
}
return res;
}
代码示例来源:origin: com.atlassian.jira/jira-rest-java-client-core
@Nullable
public static JSONObject getNestedOptionalObject(JSONObject json, final String... path) throws JSONException {
for (int i = 0; i < path.length - 1; i++) {
String s = path[i];
json = json.getJSONObject(s);
}
return json.optJSONObject(path[path.length - 1]);
}
代码示例来源:origin: com.atlassian.jira/jira-rest-java-client-core
@Nullable
public static <T> T getOptionalJsonObject(final JSONObject jsonObject, final String attributeName, final JsonObjectParser<T> jsonParser) throws JSONException {
final JSONObject res = jsonObject.optJSONObject(attributeName);
if (res == JSONObject.NULL || res == null) {
return null;
}
return jsonParser.parse(res);
}
代码示例来源:origin: com.atlassian.jira/jira-rest-java-client
@Nullable
public static JSONObject getNestedOptionalObject(JSONObject json, String... path) throws JSONException {
for (int i = 0; i < path.length - 1; i++) {
String s = path[i];
json = json.getJSONObject(s);
}
return json.optJSONObject(path[path.length - 1]);
}
代码示例来源:origin: com.atlassian.jira/jira-rest-java-client-p3
@Nullable
public static JSONObject getNestedOptionalObject(JSONObject json, String... path) throws JSONException {
for (int i = 0; i < path.length - 1; i++) {
String s = path[i];
json = json.getJSONObject(s);
}
return json.optJSONObject(path[path.length - 1]);
}
代码示例来源:origin: com.atlassian.jira/jira-rest-java-client
public static JSONArray getNestedOptionalArray(JSONObject json, String... path) throws JSONException {
for (int i = 0; json != null && i < path.length - 1; i++) {
String s = path[i];
json = json.optJSONObject(s);
}
return json == null ? null : json.optJSONArray(path[path.length - 1]);
}
代码示例来源:origin: org.openengsb.wrapped/jira-rest-java-client-core
@Nullable
public static JSONObject getNestedOptionalObject(JSONObject json, final String... path) throws JSONException {
for (int i = 0; i < path.length - 1; i++) {
String s = path[i];
json = json.getJSONObject(s);
}
return json.optJSONObject(path[path.length - 1]);
}
代码示例来源:origin: com.atlassian.jira/jira-rest-java-client-p3
public static JSONArray getNestedOptionalArray(JSONObject json, String... path) throws JSONException {
for (int i = 0; json != null && i < path.length - 1; i++) {
String s = path[i];
json = json.optJSONObject(s);
}
return json == null ? null : json.optJSONArray(path[path.length - 1]);
}
代码示例来源:origin: com.atlassian.jira/jira-rest-java-client-core
@Override
public T parse(JSONObject json) throws JSONException {
final JSONObject valueObject = json.optJSONObject(VALUE_ATTRIBUTE);
if (valueObject == null) {
throw new JSONException("Expected JSONObject with [" + VALUE_ATTRIBUTE + "] attribute present.");
}
return jsonParser.parse(valueObject);
}
}
代码示例来源:origin: com.atlassian.jira/jira-rest-java-client-p3
@Override
public T parse(JSONObject json) throws JSONException {
final JSONObject valueObject = json.optJSONObject(VALUE_ATTRIBUTE);
if (valueObject == null) {
throw new JSONException("Expected JSONObject with [" + VALUE_ATTRIBUTE + "] attribute present.");
}
return jsonParser.parse(valueObject);
}
}
代码示例来源:origin: org.apache.tez/tez-history-parser
BaseInfo(JSONObject jsonObject) throws JSONException {
final JSONObject otherInfoNode = jsonObject.getJSONObject(Constants.OTHER_INFO);
//parse tez counters
tezCounters = Utils.parseTezCountersFromJSON(
otherInfoNode.optJSONObject(Constants.COUNTERS));
//parse events
eventList = Lists.newArrayList();
Utils.parseEvents(jsonObject.optJSONArray(Constants.EVENTS), eventList);
}
代码示例来源:origin: com.atlassian.jira/jira-rest-java-client
@Override
public Comment parse(JSONObject json) throws JSONException {
final URI selfUri = JsonParseUtil.getSelfUri(json);
final Long id = JsonParseUtil.getOptionalLong(json, "id");
final String body = json.getString("body");
final BasicUser author = JsonParseUtil.parseBasicUser(json.optJSONObject("author"));
final BasicUser updateAuthor = JsonParseUtil.parseBasicUser(json.optJSONObject("updateAuthor"));
final Visibility visibility = visibilityJsonParser.parseVisibility(json);
return new Comment(selfUri, body, author, updateAuthor, JsonParseUtil.parseDateTime(json.getString("created")),
JsonParseUtil.parseDateTime(json.getString("updated")), visibility, id);
}
}
代码示例来源:origin: org.openengsb.wrapped/jira-rest-java-client-core
@Override
public Comment parse(JSONObject json) throws JSONException {
final URI selfUri = JsonParseUtil.getSelfUri(json);
final Long id = JsonParseUtil.getOptionalLong(json, "id");
final String body = json.getString("body");
final BasicUser author = JsonParseUtil.parseBasicUser(json.optJSONObject("author"));
final BasicUser updateAuthor = JsonParseUtil.parseBasicUser(json.optJSONObject("updateAuthor"));
final Visibility visibility = visibilityJsonParser.parseVisibility(json);
return new Comment(selfUri, body, author, updateAuthor, JsonParseUtil.parseDateTime(json.getString("created")),
JsonParseUtil.parseDateTime(json.getString("updated")), visibility, id);
}
}
代码示例来源:origin: com.atlassian.jira/jira-rest-java-client-core
@Override
public Comment parse(JSONObject json) throws JSONException {
final URI selfUri = JsonParseUtil.getSelfUri(json);
final Long id = JsonParseUtil.getOptionalLong(json, "id");
final String body = json.getString("body");
final BasicUser author = JsonParseUtil.parseBasicUser(json.optJSONObject("author"));
final BasicUser updateAuthor = JsonParseUtil.parseBasicUser(json.optJSONObject("updateAuthor"));
final Visibility visibility = visibilityJsonParser.parseVisibility(json);
return new Comment(selfUri, body, author, updateAuthor, JsonParseUtil.parseDateTime(json.getString("created")),
JsonParseUtil.parseDateTime(json.getString("updated")), visibility, id);
}
}
代码示例来源:origin: com.atlassian.jira/jira-rest-java-client-core
@Override
public CimIssueType parse(final JSONObject json) throws JSONException {
final IssueType issueType = issueTypeJsonParser.parse(json);
final JSONObject jsonFieldsMap = json.optJSONObject("fields");
final Map<String, CimFieldInfo> fields = (jsonFieldsMap == null) ?
Collections.<String, CimFieldInfo>emptyMap() : fieldsParser.parse(jsonFieldsMap);
return new CimIssueType(issueType.getSelf(), issueType.getId(), issueType.getName(),
issueType.isSubtask(), issueType.getDescription(), issueType.getIconUri(), fields);
}
}
代码示例来源:origin: com.atlassian.jira/jira-rest-java-client-p3
@Override
public CimIssueType parse(final JSONObject json) throws JSONException {
final IssueType issueType = issueTypeJsonParser.parse(json);
final JSONObject jsonFieldsMap = json.optJSONObject("fields");
final Map<String, CimFieldInfo> fields = (jsonFieldsMap == null) ?
Collections.<String, CimFieldInfo>emptyMap() : fieldsParser.parse(jsonFieldsMap);
return new CimIssueType(issueType.getSelf(), issueType.getId(), issueType.getName(),
issueType.isSubtask(), issueType.getDescription(), issueType.getIconUri(), fields);
}
}
内容来源于网络,如有侵权,请联系作者删除!