本文整理汇总了Java中javax.json.JsonValue.ValueType.ARRAY属性的典型用法代码示例。如果您正苦于以下问题:Java ValueType.ARRAY属性的具体用法?Java ValueType.ARRAY怎么用?Java ValueType.ARRAY使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类javax.json.JsonValue.ValueType
的用法示例。
在下文中一共展示了ValueType.ARRAY属性的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getLongArray
/**
* @param key
* @return JsonArray value or null
*/
public List<Long> getLongArray(String key, List<Long> defaultValue) {
JsonObject obj = getParsedBody();
JsonValue arrayValue = obj.get(key);
if ( arrayValue != null && arrayValue.getValueType() == ValueType.ARRAY ) {
try {
List<Long> result = new ArrayList<>();
((JsonArray) arrayValue).forEach(value -> result.add(((JsonNumber) value).longValue()));
return result;
} catch (Exception e) { // class cast, etc
Log.log(Level.FINER, this, "Exception parsing JsonArray: " + arrayValue, e);
// fall through to return default value
}
}
return defaultValue;
}
示例2: parse
public List<NameValuePair> parse(byte[] data){
List<NameValuePair> formElements = new ArrayList<NameValuePair>();
JsonReader reader = Json.createReader(new StringReader(new String(data)));
JsonObject object = reader.readObject();
for (String key: object.keySet()){
//JsonValue value = object.get(key);
if (object.get(key).getValueType() == ValueType.ARRAY){
JsonArray values = object.getJsonArray(key);
for (int i = 0; i < values.size(); i++){
formElements.add(new BasicNameValuePair(key, values.getString(i)));
}
// value
} else {
formElements.add(new BasicNameValuePair(key, object.getString(key)));
}
}
return formElements;
// return URLEncodedUtils.parse(new String(data), Charset.forName("UTF-8"));
}
示例3: next
@Override
public Event next() {
if (end == null) {
end = Boolean.FALSE;
return Event.START_ARRAY;
} else if (!aentries.hasNext()) {
if (!stack.isEmpty()) {
stack.pop();
}
end = Boolean.TRUE;
return Event.END_ARRAY;
} else {
final JsonValue val = aentries.next();
final ValueType vt = val.getValueType();
if (vt == ValueType.OBJECT) {
stack.push(new ObjectIterator((JsonObject) val));
return stack.peek().next();
} else if (vt == ValueType.ARRAY) {
stack.push(new ArrayIterator((JsonArray) val));
return stack.peek().next();
} else {
currentValue = val;
return getEvent(vt);
}
}
}
示例4: convertContentValue
@Override
public Object convertContentValue(Object value) {
if (value instanceof JsonValue) {
JsonValue val = (JsonValue) value;
Object ret = null;
ValueType typ = val.getValueType();
if (typ == ValueType.NUMBER)
ret = ((JsonNumber)val).bigDecimalValue();
else if (typ == ValueType.STRING)
ret = ((JsonString)val).getString();
else if (typ == ValueType.FALSE)
ret = Boolean.FALSE;
else if (typ == ValueType.TRUE)
ret = Boolean.TRUE;
else if (typ == ValueType.ARRAY) {
JsonArray arr = (JsonArray)val;
List<Object> vals = new ArrayList<Object>();
int sz = arr.size();
for (int i = 0; i < sz; i++) {
JsonValue v = arr.get(i);
vals.add(convertContentValue(v));
}
ret = vals;
} else if (typ == ValueType.OBJECT) {
//JsonObject obj = (JsonObject)val;
}
return ret;
}
return value;
}
示例5: getJsonValueAsArray
private static JsonArray getJsonValueAsArray(JsonValue value) {
return (value != null && value.getValueType() == ValueType.ARRAY) ? value.asJsonArray() : null;
}
示例6: handleArrayCase
private JsonValue handleArrayCase(JsonValue obj) {
if (obj.getValueType() == ValueType.ARRAY && ((JsonArray)obj).size() > 0)
return ((JsonArray)obj).get(0);
return obj;
}