org.codehaus.jettison.json.JSONObject.get()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(7.4k)|赞(0)|评价(0)|浏览(190)

本文整理了Java中org.codehaus.jettison.json.JSONObject.get()方法的一些代码示例,展示了JSONObject.get()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JSONObject.get()方法的具体详情如下:
包路径:org.codehaus.jettison.json.JSONObject
类名称:JSONObject
方法名:get

JSONObject.get介绍

[英]Get the value object associated with a key.
[中]获取与键关联的值对象。

代码示例

代码示例来源:origin: json-path/JsonPath

@Override
public Object next() 
{
  try
  {
    return jettisonUnwrap(jsonObject.get(String.valueOf(jsonKeysIt.next())));
  }
  catch( org.codehaus.jettison.json.JSONException jsonException )
  {
    throw new NoSuchElementException(jsonException.toString());
  }
}

代码示例来源:origin: com.atlassian.jira/jira-rest-java-client

private String getFieldStringUnisex(JSONObject json, String attributeName) throws JSONException {
  final JSONObject fieldsJson = json.getJSONObject(FIELDS);
  final Object fieldJson = fieldsJson.get(attributeName);
  if (fieldJson instanceof JSONObject) {
    return ((JSONObject) fieldJson).getString(VALUE_ATTR); // pre 5.0 way
  }
  return fieldJson.toString(); // JIRA 5.0 way
}

代码示例来源:origin: org.codehaus.jettison/jettison

/**
 * Get the string associated with a key.
 *
 * @param key   A key string.
 * @return      A string which is the value.
 * @throws   JSONException if the key is not found.
 */
public String getString(String key) throws JSONException {
  return get(key).toString();
}

代码示例来源:origin: org.codehaus.jettison/jettison

/**
 * Get the double value associated with a key.
 * @param key   A key string.
 * @return      The numeric value.
 * @throws JSONException if the key is not found or
 *  if the value is not a Number object and cannot be converted to a number.
 */
public double getDouble(String key) throws JSONException {
  return doGetDouble(key, get(key));
}
private double doGetDouble(String key, Object o) throws JSONException {

代码示例来源:origin: org.codehaus.jettison/jettison

/**
 * Get the boolean value associated with a key.
 *
 * @param key   A key string.
 * @return      The truth.
 * @throws   JSONException
 *  if the value is not a Boolean or the String "true" or "false".
 */
public boolean getBoolean(String key) throws JSONException {
  return doGetBoolean(key, get(key));
}
private boolean doGetBoolean(String key, Object o) throws JSONException {

代码示例来源:origin: com.jayway.jsonpath/json-path

@Override
public Object next() 
{
  try
  {
    return jettisonUnwrap(jsonObject.get(String.valueOf(jsonKeysIt.next())));
  }
  catch( org.codehaus.jettison.json.JSONException jsonException )
  {
    throw new NoSuchElementException(jsonException.toString());
  }
}

代码示例来源:origin: org.codehaus.jettison/jettison

/**
 * Get the long value associated with a key. If the number value is too
 * long for a long, it will be clipped.
 *
 * @param key   A key string.
 * @return      The long value.
 * @throws   JSONException if the key is not found or if the value cannot
 *  be converted to a long.
 */
public long getLong(String key) throws JSONException {
  return doGetLong(key, get(key));
}

代码示例来源:origin: org.codehaus.jettison/jettison

/**
 * Get the int value associated with a key. If the number value is too
 * large for an int, it will be clipped.
 *
 * @param key   A key string.
 * @return      The integer value.
 * @throws   JSONException if the key is not found or if the value cannot
 *  be converted to an integer.
 */
public int getInt(String key) throws JSONException {
  return doGetInt(key, get(key));
  
}
private int doGetInt(String key, Object o) throws JSONException {

代码示例来源:origin: com.sun.jersey/jersey-json

@SuppressWarnings("unchecked")
static <T> Map<String, T> asMap(String jsonObjectVal) throws JSONException {
  if (null == jsonObjectVal) {
    return null;
  }
  Map<String, T> result = new HashMap<String, T>();
  JSONObject sourceMap = new JSONObject(jsonObjectVal);
  Iterator<String> keyIterator = sourceMap.keys();
  while (keyIterator.hasNext()) {
    String key = keyIterator.next();
    result.put(key, (T)sourceMap.get(key));
  }
  return result;
}

代码示例来源:origin: org.codehaus.jettison/jettison

private void processElement() throws XMLStreamException {
  try {
    String nextKey = (String) node.getKeys().next();
    
    Object newObj = node.getObject().get(nextKey);
    
    processKey(nextKey, newObj);
  } catch (JSONException e) {
    throw new XMLStreamException(e);
  }
}

代码示例来源:origin: org.codehaus.jettison/jettison

/**
 * Get the JSONArray value associated with a key.
 *
 * @param key   A key string.
 * @return      A JSONArray which is the value.
 * @throws   JSONException if the key is not found or
 *  if the value is not a JSONArray.
 */
public JSONArray getJSONArray(String key) throws JSONException {
  Object o = get(key);
  if (o instanceof JSONArray) {
    return (JSONArray)o;
  }
  throw new JSONException("JSONObject[" + quote(key) +
      "] is not a JSONArray.");
}

代码示例来源:origin: org.codehaus.jettison/jettison

/**
 * Get the JSONObject value associated with a key.
 *
 * @param key   A key string.
 * @return      A JSONObject which is the value.
 * @throws   JSONException if the key is not found or
 *  if the value is not a JSONObject.
 */
public JSONObject getJSONObject(String key) throws JSONException {
  Object o = get(key);
  if (o instanceof JSONObject) {
    return (JSONObject)o;
  }
  throw new JSONException("JSONObject[" + quote(key) +
      "] is not a JSONObject.");
}

代码示例来源:origin: eBay/parallec

JSONArray jArr = (JSONArray) jObj.get("result");
if (jArr == null || jArr.length() == 0) {
  return labelList;
    continue;
  String label = (String) agentObj.get(projectionStr);

代码示例来源:origin: org.codehaus.jettison/jettison

public MappedXMLStreamReader(JSONObject obj, MappedNamespaceConvention con)
    throws JSONException, XMLStreamException {
  String rootName = (String) obj.keys().next();
  this.convention = con;
  this.nodes = new FastStack();
  this.ctx = con;
  Object top = obj.get(rootName);
  if (top instanceof JSONObject) {
    this.node = new Node(null, rootName, (JSONObject)top, convention);
  } else if (top instanceof JSONArray && !(((JSONArray)top).length() == 1 && ((JSONArray)top).get(0).equals(""))) {
    this.node = new Node(null, rootName, obj, convention);
  } else {
    node = new Node(rootName, convention);
    convention.processAttributesAndNamespaces(node, obj);
    currentValue = JSONObject.NULL.equals(top) ? null : top.toString();
  }
  nodes.push(node);
  event = START_DOCUMENT;
}

代码示例来源:origin: org.codehaus.jettison/jettison

} else {
  nextKey = (String) node.getKeys().next();
  newObj = node.getObject().get(nextKey);

代码示例来源:origin: com.atlassian.jira/jira-rest-java-client

@Nullable
public static String getNullableString(JSONObject jsonObject, String attributeName) throws JSONException {
  final Object o = jsonObject.get(attributeName);
  if (o == JSONObject.NULL) {
    return null;
  }
  return o.toString();
}

代码示例来源:origin: org.apache.tez/tez-history-parser

private void populateOtherInfo(JSONObject source, JSONObject destination) throws JSONException {
 if (source == null || destination == null) {
  return;
 }
 for (Iterator it = source.keys(); it.hasNext(); ) {
  String key = (String) it.next();
  Object val = source.get(key);
  destination.put(key, val);
 }
}

代码示例来源:origin: org.apache.apex/apex-engine

@SuppressWarnings("unchecked")
public void addDefaultValue(String className, JSONObject oper) throws Exception
{
 ObjectMapper defaultValueMapper = ObjectMapperFactory.getOperatorValueSerializer();
 Class<? extends GenericOperator> clazz = (Class<? extends GenericOperator>)classLoader.loadClass(className);
 if (clazz != null) {
  GenericOperator operIns = clazz.newInstance();
  String s = defaultValueMapper.writeValueAsString(operIns);
  oper.put("defaultValue", new JSONObject(s).get(className));
 }
}

代码示例来源:origin: org.apache.hadoop/hadoop-yarn-server-resourcemanager

private void verifyStateOfAllocations(JSONObject allocation,
  String nameToCheck, String realState) throws Exception {
 assertEquals("State of allocation is wrong", allocation.get(nameToCheck),
   realState);
}

代码示例来源:origin: GluuFederation/oxAuth

@Test
public void setClaimTestJsonObj() {
  try {
    String stringJson = StringUtil.fromBytes(Base64Util.base64urldecode("eyJzYWx0IjoibWFjbmgiLCJwcm92aWRlciI6ImlkcDEifQ=="));
    JSONObject jobj = new JSONObject(stringJson);
    JwtClaims claims = new JwtClaims();
    claims.setClaim("test_claim", jobj);
    assertEquals(jobj, claims.toJsonObject().get("test_claim"));
  } catch (Exception ex) {
    fail(ex.getMessage());
  }
}

相关文章