com.github.openjson.JSONObject.has()方法的使用及代码示例

x33g5p2x  于2022-01-22 转载在 其他  
字(2.5k)|赞(0)|评价(0)|浏览(143)

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

JSONObject.has介绍

[英]Returns true if this object has a mapping for name. The mapping may be #NULL.
[中]如果此对象具有名称映射,则返回true。映射可能为#NULL。

代码示例

代码示例来源:origin: triplea-game/triplea

private void checkUser(final JSONObject jsonObject) {
 if (!jsonObject.has("uid")) {
  throw new IllegalStateException(String.format("User %s doesn't exist.", username));
 }
 if (jsonObject.getBoolean("banned")) {
  throw new IllegalStateException("Your account is banned from the forum.");
 }
 if (!jsonObject.getBoolean("email:confirmed")) {
  throw new IllegalStateException("Your email isn't confirmed yet!");
 }
}

代码示例来源:origin: triplea-game/triplea

private String getToken(final CloseableHttpClient client, final int userId) throws IOException {
 final HttpPost post = new HttpPost(getForumUrl() + "/api/v2/users/" + userId + "/tokens");
 post.setEntity(new UrlEncodedFormEntity(
   Collections.singletonList(newPasswordParameter()),
   StandardCharsets.UTF_8));
 HttpProxy.addProxy(post);
 try (CloseableHttpResponse response = client.execute(post)) {
  final String rawJson = EntityUtils.toString(response.getEntity());
  final JSONObject jsonObject = new JSONObject(rawJson);
  if (jsonObject.has("code")) {
   final String code = jsonObject.getString("code");
   if (code.equalsIgnoreCase("ok")) {
    return jsonObject.getJSONObject("payload").getString("token");
   }
   throw new IllegalStateException(
     "Failed to retrieve Token. Code: " + code + " Message: " + jsonObject.getString("message"));
  }
  throw new IllegalStateException("Failed to retrieve Token, server did not return correct response: "
    + response.getStatusLine() + "; JSON: " + rawJson);
 }
}

代码示例来源:origin: org.wicketstuff/wicket-gchart

if (!jsonObj.has("type")) {
  throw new IllegalArgumentException("The JSON for a ColumnDeclaration must at least have a type definition");
if (jsonObj.has("label")) {
  columnDeclaration.setLabelModel(Model.of(jsonObj.getString("label")));
if (jsonObj.has("pattern")) {
  columnDeclaration.setPattern(jsonObj.getString("pattern"));
if (jsonObj.has("role")) {
  columnDeclaration.setRole(ColumnRole.valueOf(jsonObj.getString("role")));
if (jsonObj.has("properties")) {
  if (jsonObj.get("properties") instanceof JSONObject) {
    JSONObject props = (JSONObject) jsonObj.get("properties");

相关文章