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

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

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

JSONArray.getJSONObject介绍

[英]Returns the value at index if it exists and is a JSONObject.
[中]如果索引存在并且是JSONObject,则返回索引处的值。

代码示例

代码示例来源:origin: OrienteerBAP/Orienteer

private static List<OArchitectOProperty> getOPropertyListFromJson(JSONArray jsonArray) {
  List<OArchitectOProperty> properties = Lists.newArrayList();
  for (int i = 0; i < jsonArray.length(); i++) {
    properties.add(convertOPropertyFromJson(jsonArray.getJSONObject(i)));
  }
  return properties;
}

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

private static JSONObject matchCurrentVersion(final JSONArray lobbyProps, final Version currentVersion) {
 checkNotNull(lobbyProps);
 return OpenJsonUtils.stream(lobbyProps)
   .map(JSONObject.class::cast)
   .filter(props -> currentVersion.equals(new Version(props.getString("version"))))
   .findFirst()
   .orElse(lobbyProps.getJSONObject(0));
}

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

private String uploadSaveGame(final CloseableHttpClient client, final String token, final Path path)
  throws IOException {
 final HttpPost fileUpload = new HttpPost(getForumUrl() + "/api/v2/util/upload");
 fileUpload.setEntity(MultipartEntityBuilder.create()
   .addBinaryBody("files[]", path.toFile(), ContentType.APPLICATION_OCTET_STREAM, path.getFileName().toString())
   .build());
 HttpProxy.addProxy(fileUpload);
 addTokenHeader(fileUpload, token);
 try (CloseableHttpResponse response = client.execute(fileUpload)) {
  final int status = response.getStatusLine().getStatusCode();
  if (status == HttpURLConnection.HTTP_OK) {
   final String json = EntityUtils.toString(response.getEntity());
   return "\n[Savegame](" + new JSONArray(json).getJSONObject(0).getString("url") + ")";
  }
  throw new IllegalStateException("Failed to upload savegame, server returned Error Code "
    + status + "\nMessage:\n" + EntityUtils.toString(response.getEntity()));
 }
}

代码示例来源:origin: OrienteerBAP/Orienteer

/**
 * Convert JSON string with array of classes to {@link List}
 * @param json JSON string which contains JSON array of OrientDB classes.
 * @return list of {@link OArchitectOClass}
 * @throws IllegalArgumentException if json is not JSON array
 */
public static List<OArchitectOClass> fromJSON(String json) {
  Args.isTrue(json.startsWith("["), "Input JSON string is not array! json: " + json);
  List<OArchitectOClass> classes = Lists.newArrayList();
  JSONArray jsonArray = new JSONArray(json);
  for (int i = 0; i < jsonArray.length(); i++) {
    JSONObject jsonObject = jsonArray.getJSONObject(i);
    classes.add(convertOClassFromJson(jsonObject));
  }
  return classes;
}

代码示例来源:origin: OrienteerBAP/Orienteer

public void updateDashboardByJson(DashboardPanel<?> dashboard, String data) {
  final Map<String, AbstractWidget<?>> widgetsByMarkupId = new HashMap<String, AbstractWidget<?>>();
  dashboard.visitChildren(AbstractWidget.class, new IVisitor<AbstractWidget<?>, Void>() {
    @Override
    public void component(AbstractWidget<?> widget, IVisit<Void> visit) {
      widgetsByMarkupId.put(widget.getMarkupId(), widget);
      visit.dontGoDeeper();
    }
    
  });
  try {
    JSONArray jsonArray = new JSONArray(data);
    for(int i=0; i<jsonArray.length();i++) {
      JSONObject jsonWidget = jsonArray.getJSONObject(i);
      String markupId = jsonWidget.getString("id");
      AbstractWidget<?> widget = widgetsByMarkupId.get(markupId);
      GridsterWidgetBehavior behaviour = GridsterWidgetBehavior.getBehaviour(widget);
      behaviour.setCol(jsonWidget.getInt("col"));
      behaviour.setRow(jsonWidget.getInt("row"));
      behaviour.setSizeX(jsonWidget.getInt("size_x"));
      behaviour.setSizeY(jsonWidget.getInt("size_y"));
    }
  } catch (JSONException e) {
    throw new WicketRuntimeException("Can't handle dashboard update", e);
  }
}

相关文章