本文整理汇总了Java中org.json.JSONObject.isNull方法的典型用法代码示例。如果您正苦于以下问题:Java JSONObject.isNull方法的具体用法?Java JSONObject.isNull怎么用?Java JSONObject.isNull使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.json.JSONObject
的用法示例。
在下文中一共展示了JSONObject.isNull方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createOrUpdateUsingJsonObject
import org.json.JSONObject; //导入方法依赖的package包/类
@SuppressWarnings("cast")
public static some.test.Simple createOrUpdateUsingJsonObject(Realm realm, JSONObject json, boolean update)
throws JSONException {
final List<String> excludeFields = Collections.<String> emptyList();
some.test.Simple obj = realm.createObjectInternal(some.test.Simple.class, true, excludeFields);
final SimpleRealmProxyInterface objProxy = (SimpleRealmProxyInterface) obj;
if (json.has("name")) {
if (json.isNull("name")) {
objProxy.realmSet$name(null);
} else {
objProxy.realmSet$name((String) json.getString("name"));
}
}
if (json.has("age")) {
if (json.isNull("age")) {
throw new IllegalArgumentException("Trying to set non-nullable field 'age' to null.");
} else {
objProxy.realmSet$age((int) json.getInt("age"));
}
}
return obj;
}
示例2: testGetRestrictions
import org.json.JSONObject; //导入方法依赖的package包/类
public void testGetRestrictions() throws Exception
{
RepoUsage restrictions = repoAdminService.getRestrictions();
String url = "/api/admin/restrictions";
TestWebScriptServer.GetRequest req = new TestWebScriptServer.GetRequest(url);
Response response = sendRequest(req, Status.STATUS_OK, guest);
JSONObject json = new JSONObject(response.getContentAsString());
Long maxUsers = json.isNull(AbstractAdminWebScript.JSON_KEY_USERS) ? null : json.getLong(AbstractAdminWebScript.JSON_KEY_USERS);
assertEquals("Mismatched max users", restrictions.getUsers(), maxUsers);
Long maxDocuments = json.isNull(AbstractAdminWebScript.JSON_KEY_DOCUMENTS) ? null : json.getLong(AbstractAdminWebScript.JSON_KEY_DOCUMENTS);
assertEquals("Mismatched max documents", restrictions.getDocuments(), maxDocuments);
}
示例3: parseError
import org.json.JSONObject; //导入方法依赖的package包/类
public static WebApiException parseError(JSONObject answer) {
if (answer.has("errorCode")) {
int code = answer.getInt("errorCode");
String message = answer.getString("errorMessage");
if (!answer.isNull("debug")) {
message += " : " + answer.getString("debug");
}
return new WebApiException(code, message);
} else {
return new WebApiException(-1, "Unknown error.");
}
}
示例4: getExtraInfos
import org.json.JSONObject; //导入方法依赖的package包/类
public void getExtraInfos(JSONObject json) {
medias.clear();
if (json!=null) {
try {
if (!json.isNull("id")) id = json.getInt("id");
if (!json.isNull("account")) {
JSONObject acc = json.getJSONObject("account");
username = acc.getString("acct");
if (!acc.isNull("id")) autid=acc.getInt("id");
String avatar = acc.getString("avatar");
if (avatar!=null && avatar.startsWith("http")) usericonurl=avatar;
}
if (!json.isNull("created_at")) date=json.getString("created_at");
if (!json.isNull("url")) tooturl=json.getString("url");
if (!json.isNull("in_reply_to_id")) parentid=json.getInt("in_reply_to_id");
if (json.isNull("favourited")) boosted=false;
else boosted = json.getBoolean("favourited");
JSONArray meds = json.getJSONArray("media_attachments");
if (meds!=null) {
for (int i=0;i<meds.length();i++) {
JSONObject mm = meds.getJSONObject(i);
if (!mm.isNull("url")) medias.add(mm.getString("url"));
else if (!mm.isNull("remote_url")) medias.add(mm.getString("remote_url"));
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
示例5: getRoomResponse
import org.json.JSONObject; //导入方法依赖的package包/类
public static ArrayList<RoomInfo> getRoomResponse(String rawString) throws JSONException {
JSONObject json = makeProperJsonObject(rawString);
if (!json.isNull(KEY_ROOM_LIST)) {
JSONArray jsonRooms = json.getJSONArray(KEY_ROOM_LIST);
ArrayList<RoomInfo> rooms = new ArrayList<>(jsonRooms.length());
for (int i = 0; i < jsonRooms.length(); i++) {
JSONObject r = jsonRooms.getJSONObject(i);
rooms.add(constructRoom(r));
}
return rooms;
}
return null;
}
示例6: createOrUpdateUsingJsonObject
import org.json.JSONObject; //导入方法依赖的package包/类
@SuppressWarnings("cast")
public static some.test.Booleans createOrUpdateUsingJsonObject(Realm realm, JSONObject json, boolean update)
throws JSONException {
final List<String> excludeFields = Collections.<String> emptyList();
some.test.Booleans obj = realm.createObjectInternal(some.test.Booleans.class, true, excludeFields);
final BooleansRealmProxyInterface objProxy = (BooleansRealmProxyInterface) obj;
if (json.has("done")) {
if (json.isNull("done")) {
throw new IllegalArgumentException("Trying to set non-nullable field 'done' to null.");
} else {
objProxy.realmSet$done((boolean) json.getBoolean("done"));
}
}
if (json.has("isReady")) {
if (json.isNull("isReady")) {
throw new IllegalArgumentException("Trying to set non-nullable field 'isReady' to null.");
} else {
objProxy.realmSet$isReady((boolean) json.getBoolean("isReady"));
}
}
if (json.has("mCompleted")) {
if (json.isNull("mCompleted")) {
throw new IllegalArgumentException("Trying to set non-nullable field 'mCompleted' to null.");
} else {
objProxy.realmSet$mCompleted((boolean) json.getBoolean("mCompleted"));
}
}
if (json.has("anotherBoolean")) {
if (json.isNull("anotherBoolean")) {
throw new IllegalArgumentException("Trying to set non-nullable field 'anotherBoolean' to null.");
} else {
objProxy.realmSet$anotherBoolean((boolean) json.getBoolean("anotherBoolean"));
}
}
return obj;
}
示例7: getPlace
import org.json.JSONObject; //导入方法依赖的package包/类
private HashMap<String, String> getPlace(JSONObject googlePlaceJson) {
HashMap<String, String> googlePlaceMap = new HashMap<String, String>();
String placeName = "-NA-";
String vicinity = "-NA-";
String latitude = "";
String longitude = "";
String reference = "";
Log.d("getPlace", "Entered");
try {
if (!googlePlaceJson.isNull("name")) {
placeName = googlePlaceJson.getString("name");
}
if (!googlePlaceJson.isNull("vicinity")) {
vicinity = googlePlaceJson.getString("vicinity");
}
latitude = googlePlaceJson.getJSONObject("geometry").getJSONObject("location").getString("lat");
longitude = googlePlaceJson.getJSONObject("geometry").getJSONObject("location").getString("lng");
reference = googlePlaceJson.getString("reference");
googlePlaceMap.put("place_name", placeName);
googlePlaceMap.put("vicinity", vicinity);
googlePlaceMap.put("lat", latitude);
googlePlaceMap.put("lng", longitude);
googlePlaceMap.put("reference", reference);
Log.d("getPlace", "Putting Places");
} catch (JSONException e) {
Log.d("getPlace", "Error");
e.printStackTrace();
}
return googlePlaceMap;
}
示例8: getMovieCreditCastList
import org.json.JSONObject; //导入方法依赖的package包/类
/**
* Gets a List of credit cast.
* @param jobj object
* @param object name of the sub object
* @param name name
* @return list of movie credit cast
* @throws JSONException
*/
public static List<MovieCreditCast> getMovieCreditCastList(JSONObject jobj, String object,
String name)
throws JSONException {
if (jobj.isNull(object)) {
return Collections.emptyList();
} else {
JSONObject jobject = jobj.getJSONObject(object);
if (jobject.isNull(name)){
return Collections.emptyList();
} else {
List<MovieCreditCast> list = new ArrayList<>();
JSONArray jArray = jobject.getJSONArray(name);
JSONObject jsonObject;
for (int i = 0; i < jArray.length(); i++) {
jsonObject = jArray.getJSONObject(i);
MovieCreditCast creditCast = new MovieCreditCast(
jsonObject.getInt("id"),
jsonObject.getString("character"),
jsonObject.getString("title"),
jsonObject.getString("poster_path"),
jsonObject.getString("release_date")
);
list.add(i, creditCast);
}
Collections.sort(list, new Comparator<MovieCreditCast>() {
@Override public int compare(MovieCreditCast p1, MovieCreditCast p2) {
return p2.getReleaseYear() - p1.getReleaseYear(); // Descending
}
});
return list;
}
}
}
示例9: buildUser
import org.json.JSONObject; //导入方法依赖的package包/类
public User buildUser (JSONObject json) {
handleBuildError(json);
/* Basic Information */
String id = json.has("webhook_id") ? json.getString("webhook_id") : json.getString("id");
String name = json.getString("username");
String discriminator = json.getString("discriminator");
/* Require Email OAuth2 */
String avatar = json.has("avatar") && !json.isNull("avatar") ? json.getString("avatar") : null;
String email = json.has("email") && !json.isNull("email") ? json.getString("email") : null;
/* Boolean Information */
boolean isBot = json.has("bot") && json.getBoolean("bot");
boolean isWebHook = json.has("webhook_id");
boolean isVerified = json.has("verified") && json.getBoolean("verified");
boolean isMFAEnabled = json.has("mfa_enabled") && json.getBoolean("mfa_enabled");
User user = new User(identity, id)
.setName(name)
.setDiscriminator(discriminator)
.setAvatar(avatar)
.setEmail(email)
.setBot(isBot)
.setWebHook(isWebHook)
.setVerified(isVerified)
.setMFAEnabled(isMFAEnabled);
identity.addUser(user);
return user;
}
示例10: getGroupUsersFromJson
import org.json.JSONObject; //导入方法依赖的package包/类
public List<GroupUser> getGroupUsersFromJson(JSONObject obj, Map<String, String> roles) {
JSONArray members = obj.getJSONArray("members");
List<GroupUser> guList = new ArrayList<>();
for (int i = 0; i < members.length(); i++) {
JSONObject item = members.getJSONObject(i);
JSONObject user = item.getJSONObject("user");
String username = user.getString("username");
String id = user.getString("id");
String dis = String.valueOf(user.get("discriminator")); //Sometimes returns an int or string... just cast
// the obj to string
String avatarId = (user.isNull("avatar") ? "" : user.getString("avatar"));
String role = "User";
UserImpl userImpl;
if (api.isUserKnown(id)) {
userImpl = (UserImpl) api.getUserById(id);
} else {
userImpl = new UserImpl(username, id, id, api);
userImpl.setAvatar(user.isNull("avatar") ? "" : "https://cdn.discordapp.com/avatars/" + id + "/" +
avatarId + ".jpg");
}
if (item.getJSONArray("roles").length() > 0)
role = roles.get(item.getJSONArray("roles").opt(0));
guList.add(new GroupUser(userImpl, role, dis));
}
return guList;
}
示例11: UserEvent
import org.json.JSONObject; //导入方法依赖的package包/类
public UserEvent(JSONObject event) {
if(!event.isNull("display_html")) displayHtml = event.getString("display_html");
if(!event.isNull("date")) date = event.getString("date");
if(!event.isNull("beatmap_id")) beatMapID = Long.parseLong(event.getString("beatmap_id"));
if(!event.isNull("beatmapset_id")) beatMapSetID = Long.parseLong(event.getString("beatmapset_id"));
if(!event.isNull("epicfactor")) epicfactor = Long.parseLong(event.getString("epicfactor"));
}
示例12: groupUpdate
import org.json.JSONObject; //导入方法依赖的package包/类
private void groupUpdate(JSONObject json, int sequence) {
Group group = (Group) identity.getClient().getGroup(json.getString("id"));
if (group == null) {
logger.log(LogLevel.FETAL, "[UNKNOWN GROUP] [CHANNEL_UPDATE_EVENT_HANDLER] ID: " + json.getString("id"));
return;
}
String ownerId = json.getString("owner_id");
IUser owner = group.getRecipient(ownerId);
if (owner == null) {
// Not GroupOwnerUpdateEvent
if (ownerId.equals(group.getOwner().getId())) {
owner = group.getOwner();
} else {
logger.log(LogLevel.FETAL, "[UNKNOWN GROUP OWNER] [CHANNEL_UPDATE_EVENT_HANDLER] ID: " + ownerId);
return;
}
}
String name = json.isNull("name") ? null : json.getString("name");
String icon = json.isNull("icon") ? null : json.getString("icon");
if (!Objects.equals(owner, group.getOwner())) {
IUser oldOwner = group.getOwner();
group.setOwnerId(ownerId);
dispatchEvent(new GroupOwnerUpdateEvent(identity, sequence, group, oldOwner));
}
if (!Objects.equals(name, group.getName())) {
String oldName = group.getName();
group.setName(name);
dispatchEvent(new GroupNameUpdateEvent(identity, sequence, group, oldName));
}
if (!Objects.equals(icon, group.getIconHash())) {
String oldIcon = group.getIconHash();
group.setIcon(icon);
dispatchEvent(new GroupIconUpdateEvent(identity, sequence, group, oldIcon));
}
}
示例13: BeatMap
import org.json.JSONObject; //导入方法依赖的package包/类
public BeatMap(JSONObject map) {
if(!map.isNull("approved")){
beatMapState = BeatMapState.byId(Integer.parseInt(map.getString("approved")));
} else {
beatMapState = BeatMapState.PENDING;
}
if(!map.isNull("genre_id")) beatMapGenre = BeatMapGenre.byId(Integer.parseInt(map.getString("genre_id")));
if(!map.isNull("mode")) gameMode = GameMode.byId(Integer.parseInt(map.getString("mode")));
if(!map.isNull("approved_date")) appovedDate = map.getString("approved_date");
if(!map.isNull("last_update")) lastUpdate = map.getString("last_update");
if(!map.isNull("artist")) artist = map.getString("artist");
if(!map.isNull("creator")) creator = map.getString("creator");
if(!map.isNull("title")) title = map.getString("title");
if(!map.isNull("version")) difficulty = map.getString("version");
if(!map.isNull("file_md5")) MD5 = map.getString("file_md5");
if(!map.isNull("tags")) tags = map.getString("tags").split(" ");
if(!map.isNull("beatmap_id")) beatMapID = Integer.parseInt(map.getString("beatmap_id"));
if(!map.isNull("beatmapset_id")) beatMapSetID = Integer.parseInt(map.getString("beatmapset_id"));
if(!map.isNull("bpm")) BPM = Double.parseDouble(map.getString("bpm"));
if(!map.isNull("diff_size")) CS = Double.parseDouble(map.getString("diff_size"));
if(!map.isNull("diff_overall")) OD = Double.parseDouble(map.getString("diff_overall"));
if(!map.isNull("diff_approach")) AR = Double.parseDouble(map.getString("diff_approach"));
if(!map.isNull("diff_drain")) HP = Double.parseDouble(map.getString("diff_drain"));
if(!map.isNull("hit_length")) hitLength = Integer.parseInt(map.getString("hit_length"));
if(!map.isNull("total_length")) totalLength = Integer.parseInt(map.getString("total_length"));
if(!map.isNull("favourite_count")) favoriteCount = Integer.parseInt(map.getString("favourite_count"));
if(!map.isNull("playcount")) playCount = Integer.parseInt(map.getString("playcount"));
if(!map.isNull("passcount")) passCount = Integer.parseInt(map.getString("passcount"));
if(!map.isNull("max_combo")) maxCombo = Integer.parseInt(map.getString("max_combo"));
if(!map.isNull("difficultyrating")) stars = Double.parseDouble(map.getString("difficultyrating"));
}
示例14: getArrayValue
import org.json.JSONObject; //导入方法依赖的package包/类
public static String getArrayValue(JSONObject jobj, String name)
throws JSONException {
if (jobj.isNull(name)) {
return null;
} else {
JSONArray jArray = jobj.getJSONArray(name);
String result = jArray.getString(0);
for (int i = 1; i < jArray.length(); i++) {
result += "," + jArray.getString(i);
}
return result;
}
}
示例15: update
import org.json.JSONObject; //导入方法依赖的package包/类
@Override
public void update(JSONObject json) {
if(!json.isNull("username")) username = json.getString("username");
if(!json.isNull("discriminator")) discriminator = (short)json.getInt("discriminator");
if(!json.isNull("avatar")) avatar = json.getString("avatar");
bot = json.optBoolean("bot");
}