本文整理汇总了Java中javax.json.JsonNumber.intValue方法的典型用法代码示例。如果您正苦于以下问题:Java JsonNumber.intValue方法的具体用法?Java JsonNumber.intValue怎么用?Java JsonNumber.intValue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.json.JsonNumber
的用法示例。
在下文中一共展示了JsonNumber.intValue方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: toJavaObject
import javax.json.JsonNumber; //导入方法依赖的package包/类
/**
* Converts a {@link JsonValue} to its corresponding Java object. Values of type {@link
* JsonObject} or {@link JsonArray} are converted as specified by {@link #toJavaMap} and {@link
* #toJavaList}, respectively.
*/
@Nullable
public static Object toJavaObject(JsonValue value) {
switch (value.getValueType()) {
case ARRAY:
return toJavaList((JsonArray) value);
case FALSE:
return Boolean.FALSE;
case NULL:
return null;
case NUMBER:
JsonNumber number = (JsonNumber) value;
return number.isIntegral() ? number.intValue() : number.doubleValue();
case OBJECT:
return toJavaMap((JsonObject) value);
case STRING:
return ((JsonString) value).getString();
case TRUE:
return Boolean.TRUE;
default:
throw new VerifyException("Json value with unknown type: " + value);
}
}
示例2: fromJSON
import javax.json.JsonNumber; //导入方法依赖的package包/类
public static SessionRating fromJSON(JsonObject sessionRatingJson) {
String id = getStringFromJson("id", sessionRatingJson);
String session = getStringFromJson("session", sessionRatingJson);
String attendeeId = getStringFromJson("attendeeId", sessionRatingJson);
String _rev = getStringFromJson("_rev", sessionRatingJson);
String _id = getStringFromJson("_id", sessionRatingJson);
int rating = 0;
if (sessionRatingJson.containsKey("rating")) {
JsonNumber ratingJson = sessionRatingJson.getJsonNumber("rating");
if (ratingJson != null) {
rating = ratingJson.intValue();
}
}
SessionRating sessionRating = new SessionRating(id, session, attendeeId, rating, _id, _rev);
return sessionRating;
}
示例3: getIntvalue
import javax.json.JsonNumber; //导入方法依赖的package包/类
/**
* Returns the int value for a name
* @param name
* @return the value
*/
public int getIntvalue(String name) {
if (name == null) {
throw new NullPointerException("name is null!");
}
if (isInvalidJsonStream()) {
return -1;
}
try {
JsonReader reader = Json.createReader(new StringReader(jsonResult));
JsonStructure jsonst = reader.read();
JsonObject object = (JsonObject) jsonst;
JsonNumber value = (JsonNumber) object.get(name);
if (value == null) {
return -1;
}
return value.intValue();
} catch (Exception e) {
this.parseException = e;
return -1;
}
}
示例4: getErrorType
import javax.json.JsonNumber; //导入方法依赖的package包/类
/**
* Returns the error_type in case of failure
* @return the error_type in case of failure, -1 if no error
*/
public int getErrorType() {
if (isInvalidJsonStream()) {
return 0;
}
try {
JsonReader reader = Json.createReader(new StringReader(jsonResult));
JsonStructure jsonst = reader.read();
JsonObject object = (JsonObject) jsonst;
JsonString status = (JsonString) object.get("status");
if (status == null) {
return -1;
}
JsonNumber errorType = (JsonNumber) object.get("error_type");
if (errorType == null) {
return -1;
}
else {
return errorType.intValue();
}
} catch (Exception e) {
this.parseException = e;
return -1;
}
}
示例5: getSex
import javax.json.JsonNumber; //导入方法依赖的package包/类
public ULoginUser.Sex getSex(JsonObject obj){
JsonNumber sexNum = obj.getJsonNumber("sex");
if(sexNum==null){
return null;
}
int i = sexNum.intValue();
if(i<0||i>3){
return null;
}
return ULoginUser.Sex.values()[i];
}
示例6: decode
import javax.json.JsonNumber; //导入方法依赖的package包/类
/**
* IdTokenのデコード
*
* @return IdTokenObject
* @throws DataFormatException
*/
public IdTokenObject decode() throws DataFormatException {
HashMap<String, String> idToken = this.splitIdToken();
// Header
String jsonHeader = idToken.get("header");
JsonReader jsonHeaderReader = Json.createReader(new StringReader(jsonHeader));
JsonObject rootHeader = jsonHeaderReader.readObject();
jsonHeaderReader.close();
JsonString typeString = rootHeader.getJsonString("typ");
String type = typeString.getString();
JsonString algorithmString = rootHeader.getJsonString("alg");
String algorithm = algorithmString.getString();
// Payload
String jsonPayload = idToken.get("payload");
JsonReader jsonPayloadReader = Json.createReader(new StringReader(jsonPayload));
JsonObject rootPayload = jsonPayloadReader.readObject();
jsonPayloadReader.close();
JsonString issString = rootPayload.getJsonString("iss");
String iss = issString.getString();
JsonString userIdString = rootPayload.getJsonString("user_id");
String userId = userIdString.getString();
JsonString audString = rootPayload.getJsonString("aud");
ArrayList<String> aud = new ArrayList<String>();
aud.add(audString.getString());
JsonNumber expString = rootPayload.getJsonNumber("exp");
int exp = expString.intValue();
JsonNumber iatString = rootPayload.getJsonNumber("iat");
int iat = iatString.intValue();
JsonString nonceString = rootPayload.getJsonString("nonce");
String nonce = nonceString.getString();
// signature
String signature = idToken.get("signature");
// デコードした値を格納
return new IdTokenObject(type, algorithm, iss, userId, aud, nonce, exp, iat, signature);
}