本文整理了Java中org.codehaus.jettison.json.JSONArray.optJSONObject()
方法的一些代码示例,展示了JSONArray.optJSONObject()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JSONArray.optJSONObject()
方法的具体详情如下:
包路径:org.codehaus.jettison.json.JSONArray
类名称:JSONArray
方法名:optJSONObject
[英]Get the optional JSONObject associated with an index. Null is returned if the key is not found, or null if the index has no value, or if the value is not a JSONObject.
[中]获取与索引关联的可选JSONObject。如果找不到键,则返回Null;如果索引没有值,或该值不是JSONObject,则返回Null。
代码示例来源:origin: com.tinkerpop.blueprints/blueprints-rexster-graph
public Iterable<Index<? extends Element>> getIndices() {
List<Index<? extends Element>> indices = new ArrayList<Index<? extends Element>>();
JSONArray json = RestHelper.getResultArray(this.graphURI + RexsterTokens.SLASH_INDICES);
for (int ix = 0; ix < json.length(); ix++) {
JSONObject index = json.optJSONObject(ix);
Class c;
String clazz = index.optString(RexsterTokens.CLASS);
if (clazz.toLowerCase().contains(RexsterTokens.VERTEX))
c = Vertex.class;
else if (clazz.toLowerCase().contains(RexsterTokens.EDGE))
c = Edge.class;
else
throw new RuntimeException("Can not determine whether " + clazz + " is a vertex or edge class");
indices.add(new RexsterIndex(this, index.optString(RexsterTokens.NAME), c));
}
return indices;
}
代码示例来源:origin: cwensel/cascading
private Map<String, Map<String, Long>> parseDagCounters( JSONObject countersNode ) throws JSONException
{
if( countersNode == null )
return null;
JSONArray counterGroupNodes = countersNode.optJSONArray( ATSConstants.COUNTER_GROUPS );
if( counterGroupNodes == null )
return null;
Map<String, Map<String, Long>> counters = new HashMap<>();
int numCounterGroups = counterGroupNodes.length();
for( int i = 0; i < numCounterGroups; i++ )
parseCounterGroup( counters, counterGroupNodes.optJSONObject( i ) );
return counters;
}
代码示例来源:origin: cascading/cascading-hadoop2-tez-stats
private Map<String, Map<String, Long>> parseDagCounters( JSONObject countersNode ) throws JSONException
{
if( countersNode == null )
return null;
JSONArray counterGroupNodes = countersNode.optJSONArray( ATSConstants.COUNTER_GROUPS );
if( counterGroupNodes == null )
return null;
Map<String, Map<String, Long>> counters = new HashMap<>();
int numCounterGroups = counterGroupNodes.length();
for( int i = 0; i < numCounterGroups; i++ )
parseCounterGroup( counters, counterGroupNodes.optJSONObject( i ) );
return counters;
}
代码示例来源:origin: com.tinkerpop.blueprints/blueprints-rexster-graph
protected void fillBuffer(final Queue<Edge> queue, final int start, final int end) {
final JSONObject object = RestHelper.get(this.uri + this.createSeparator() + RexsterTokens.REXSTER_OFFSET_START + RexsterTokens.EQUALS + start + RexsterTokens.AND + RexsterTokens.REXSTER_OFFSET_END + RexsterTokens.EQUALS + end);
JSONArray array = object.optJSONArray(RexsterTokens.RESULTS);
for (int ix = 0; ix < array.length(); ix++) {
queue.add(new RexsterEdge(array.optJSONObject(ix), this.graph));
}
}
}
代码示例来源:origin: com.tinkerpop.blueprints/blueprints-rexster-graph
protected void fillBuffer(final Queue<Vertex> queue, final int start, final int end) {
final JSONObject object = RestHelper.get(this.uri + this.createSeparator() + RexsterTokens.REXSTER_OFFSET_START + RexsterTokens.EQUALS + start + RexsterTokens.AND + RexsterTokens.REXSTER_OFFSET_END + RexsterTokens.EQUALS + end);
JSONArray array = object.optJSONArray(RexsterTokens.RESULTS);
for (int ix = 0; ix < array.length(); ix++) {
queue.add(new RexsterVertex(array.optJSONObject(ix), this.graph));
}
}
}
代码示例来源:origin: apache/stanbol
public static enum TYPE_STRICT {any,all,should};
代码示例来源:origin: org.apache.tez/tez-history-parser
/**
* Parse events from json
*
* @param eventNodes
* @param eventList
* @throws JSONException
*/
public static void parseEvents(JSONArray eventNodes, List<Event> eventList) throws
JSONException {
if (eventNodes == null) {
return;
}
for (int i = 0; i < eventNodes.length(); i++) {
JSONObject eventNode = eventNodes.optJSONObject(i);
final String eventInfo = eventNode.optString(Constants.EVENT_INFO);
final String eventType = eventNode.optString(Constants.EVENT_TYPE);
final long time = eventNode.optLong(Constants.EVENT_TIME_STAMP);
Event event = new Event(eventInfo, eventType, time);
eventList.add(event);
}
}
代码示例来源:origin: apache/stanbol
assertTrue("Fields MUST contain at least a single value!",jValues.length() > 0);
for(int i=0;i<jValues.length();i++){
JSONObject fieldValue = jValues.optJSONObject(i);
assertNotNull("Values for field "+key+" does contain an value " +
"that is not an JSONObject "+jValues.optString(i),
代码示例来源:origin: org.apache.tez/tez-api
private TezCountersProto.Builder parseDagCounters(JSONObject countersNode)
throws JSONException {
if (countersNode == null) {
return null;
}
TezCountersProto.Builder countersProto = TezCountersProto.newBuilder();
final JSONArray counterGroupNodes = countersNode.optJSONArray(ATSConstants.COUNTER_GROUPS);
if (counterGroupNodes != null) {
final int numCounterGroups = counterGroupNodes.length();
for (int i = 0; i < numCounterGroups; i++) {
TezCounterGroupProto.Builder counterGroupBuilder =
parseCounterGroup(counterGroupNodes.optJSONObject(i));
if (counterGroupBuilder != null) {
countersProto.addCounterGroups(counterGroupBuilder);
}
}
}
return countersProto;
}
代码示例来源:origin: dbs-leipzig/gradoop
JSONArray array = jsonObject.optJSONArray(key);
boolean listOrObject = array.optJSONObject(0) != null;
String stringValue = listOrObject ? array.optJSONObject(i).toString() : array.optString(i);
代码示例来源:origin: org.apache.tez/tez-history-parser
jsonObject.optJSONObject(Constants.ENTITY));
} else {
JSONObject subJsonObject = relatedEntities.optJSONObject(0);
if (subJsonObject != null) {
String nodeId = subJsonObject.optString(Constants.ENTITY_TYPE);
subJsonObject = relatedEntities.optJSONObject(1);
if (subJsonObject != null) {
String containerId = subJsonObject.optString(Constants.ENTITY_TYPE);
代码示例来源:origin: org.apache.tez/tez-history-parser
if (counterGroupNodes != null) {
for (int i = 0; i < counterGroupNodes.length(); i++) {
JSONObject counterGroupNode = counterGroupNodes.optJSONObject(i);
final String groupName = counterGroupNode.optString(Constants.COUNTER_GROUP_NAME);
final String groupDisplayName = counterGroupNode.optString(
JSONObject counterNode = counterNodes.optJSONObject(j);
final String counterName = counterNode.getString(Constants.COUNTER_NAME);
final String counterDisplayName =
代码示例来源:origin: thinkaurelius/faunus
private static void fromJSONEdges(final FaunusVertex vertex, final JSONArray edges, final Direction direction) throws JSONException, IOException {
if (null != edges) {
for (int i = 0; i < edges.length(); i++) {
final JSONObject edge = edges.optJSONObject(i);
FaunusEdge faunusEdge = null;
if (direction.equals(Direction.IN)) {
faunusEdge = (FaunusEdge) graphson.edgeFromJson(edge, new FaunusVertex(edge.optLong(GraphSONTokens._OUT_V)), vertex);
} else if (direction.equals(Direction.OUT)) {
faunusEdge = (FaunusEdge) graphson.edgeFromJson(edge, vertex, new FaunusVertex(edge.optLong(GraphSONTokens._IN_V)));
}
if (faunusEdge != null) {
vertex.addEdge(direction, faunusEdge);
}
}
}
}
代码示例来源:origin: apache/stanbol
@Test
public void testDefaultRangeConstraintDatatypeProperty() throws IOException, JSONException {
FieldQueryTestCase test = new FieldQueryTestCase(
"{"+
"'selected': [ 'http:\\/\\/www.test.org\\/test#field'], " +
"'constraints': [{ " +
"'type': 'range', " +
"'field': 'http:\\/\\/www.test.org\\/test#field', " +
"'lowerBound': 1000," +
"'inclusive': true," +
"}]" +
"}",
false); //expect BadRequest
//now execute the test
RequestExecutor re = executeQuery(test);
JSONObject jQuery = assertResponseQuery(re.getContent());
JSONArray jConstraints = jQuery.optJSONArray("constraints");
assertNotNull("Result Query does not contain the constraints Array",jConstraints);
assertTrue("Result Query Constraint Array does not contain the expected Constraint",
jConstraints.length() == 1);
JSONObject jConstraint = jConstraints.optJSONObject(0);
assertNotNull("Constraint Array does not contain JSONObjects",jConstraint);
assertTrue("Returned Query does not contain the default data type",jConstraint.has("datatype")); }
}
代码示例来源:origin: apache/stanbol
@Test
public void testValueConstraintDefaultDataType() throws IOException, JSONException {
FieldQueryTestCase test = new FieldQueryTestCase(
"{"+
"'selected': [ 'http:\\/\\/www.test.org\\/test#field'], " +
"'constraints': [{ " +
"'type': 'value'," +
"'value': 'Paris'," +
"'field': 'http:\\/\\/www.test.org\\/test#field'" +
"}]," +
"}",
false); //expect BadRequest
//now execute the test
RequestExecutor re = executeQuery(test);
JSONObject jQuery = assertResponseQuery(re.getContent());
JSONArray jConstraints = jQuery.optJSONArray("constraints");
assertNotNull("Result Query does not contain the constraints Array",jConstraints);
assertTrue("Result Query Constraint Array does not contain the expected Constraint",
jConstraints.length() == 1);
JSONObject jConstraint = jConstraints.optJSONObject(0);
assertNotNull("Constraint Array does not contain JSONObjects",jConstraint);
assertTrue("Returned Query does not contain the default data type",jConstraint.has("datatype"));
}
@Test
代码示例来源:origin: apache/stanbol
@Test
public void testDefaultTextConstraintPatternTypeProperty() throws IOException, JSONException {
FieldQueryTestCase test = new FieldQueryTestCase(
"{"+
"'selected': [ 'http:\\/\\/www.test.org\\/test#field'], " +
"'constraints': [{ " +
"'type': 'text', " +
"'text': 'Paris', " +
"'field': 'http:\\/\\/www.test.org\\/test#field', " +
"}]" +
"}",
false); //expect BadRequest
//now execute the test
RequestExecutor re = executeQuery(test);
JSONObject jQuery = assertResponseQuery(re.getContent());
JSONArray jConstraints = jQuery.optJSONArray("constraints");
assertNotNull("Result Query does not contain the constraints Array",jConstraints);
assertTrue("Result Query Constraint Array does not contain the expected Constraint",
jConstraints.length() == 1);
JSONObject jConstraint = jConstraints.optJSONObject(0);
assertNotNull("Constraint Array does not contain JSONObjects",jConstraint);
assertTrue("The 'patternType' property MUST BE set for returned TextConstraints",
jConstraint.has("patternType"));
assertEquals("Default for patternType MUST BE 'none'",
"none", jConstraint.getString("patternType"));
}
@Test
代码示例来源:origin: apache/stanbol
assertEquals("Result Query is expected to have a single constraint",
1, jConstraints.length());
JSONObject constraint = jConstraints.optJSONObject(0);
assertNotNull("'constraints' array does not contain a JSONObject but "+jConstraints.get(0),
constraint);
内容来源于网络,如有侵权,请联系作者删除!