org.json.JSONObject.toMap()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(10.1k)|赞(0)|评价(0)|浏览(316)

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

JSONObject.toMap介绍

[英]Returns a java.util.Map containing all of the entries in this object. If an entry in the object is a JSONArray or JSONObject it will also be converted.

Warning: This method assumes that the data structure is acyclical.
[中]返回一个java。util。包含此对象中所有项的映射。如果对象中的条目是JSONArray或JSONObject,那么它也将被转换。
警告:此方法假定数据结构是非循环的。

代码示例

代码示例来源:origin: loklak/loklak_server

@Override
public boolean writeEntry(JSONObject json) throws IOException {
  if (json == null) return false;
  if (this.elasticsearch_client == null) return true;
  if (!json.has(AbstractObjectEntry.TIMESTAMP_FIELDNAME)) json.put(AbstractObjectEntry.TIMESTAMP_FIELDNAME, AbstractObjectEntry.utcFormatter.print(System.currentTimeMillis()));
  boolean newDoc = this.elasticsearch_client.writeMap(this.index_name, json.toMap(), "local", String.valueOf(json.get("id_str")));
  this.indexWrite.incrementAndGet();
  return newDoc;
}

代码示例来源:origin: loklak/loklak_server

/**
   * Returns a java.util.List containing all of the elements in this array.
   * If an element in the array is a JSONArray or JSONObject it will also
   * be converted.
   * <p>
   * Warning: This method assumes that the data structure is acyclical.
   *
   * @return a java.util.List containing the elements of this array
   */
  public List<Object> toList() {
    List<Object> results = new ArrayList<Object>(this.myArrayList.size());
    for (Object element : this.myArrayList) {
      if (element == null || JSONObject.NULL.equals(element)) {
        results.add(null);
      } else if (element instanceof JSONArray) {
        results.add(((JSONArray) element).toList());
      } else if (element instanceof JSONObject) {
        results.add(((JSONObject) element).toMap());
      } else {
        results.add(element);
      }
    }
    return results;
  }
}

代码示例来源:origin: loklak/loklak_server

/**
   * Returns a java.util.Map containing all of the entries in this object.
   * If an entry in the object is a JSONArray or JSONObject it will also
   * be converted.
   * <p>
   * Warning: This method assumes that the data structure is acyclical.
   *
   * @return a java.util.Map containing the entries of this object
   */
  public Map<String, Object> toMap() {
    Map<String, Object> results = new HashMap<String, Object>();
    for (Entry<String, Object> entry : this.entrySet()) {
      Object value;
      if (entry.getValue() == null || NULL.equals(entry.getValue())) {
        value = null;
      } else if (entry.getValue() instanceof JSONObject) {
        value = ((JSONObject) entry.getValue()).toMap();
      } else if (entry.getValue() instanceof JSONArray) {
        value = ((JSONArray) entry.getValue()).toList();
      } else {
        value = entry.getValue();
      }
      results.put(entry.getKey(), value);
    }
    return results;
  }
}

代码示例来源:origin: loklak/loklak_server

private List<BulkWriteEntry> testBulk(int from, int to) {
  List<BulkWriteEntry> bulk = new ArrayList<>();
  for (int i = from; i < to; i++) {
    JSONObject testJson = JSONObjectTest.testJson(true);
    BulkWriteEntry entry = new BulkWriteEntry("id_" + i, "testtype", null, null, testJson.toMap());    
    bulk.add(entry);
  }
  return bulk;
}

代码示例来源:origin: loklak/loklak_server

@Override
public boolean writeEntry(IndexEntry<IndexObject> entry) throws IOException {
  boolean newDoc = this.objectCache.put(entry.getId(), entry.getObject()) == null;
  this.existCache.add(entry.getId());
  // record user into search index
  JSONObject json = entry.getObject().toJSON();
  if (json == null) return false;
  if (!json.has(AbstractObjectEntry.TIMESTAMP_FIELDNAME)) json.put(AbstractObjectEntry.TIMESTAMP_FIELDNAME, AbstractObjectEntry.utcFormatter.print(System.currentTimeMillis()));
  if (this.elasticsearch_client == null) return newDoc;
  newDoc = this.elasticsearch_client.writeMap(this.index_name, json.toMap(), entry.getType().toString(), entry.getId());
  this.indexWrite.incrementAndGet();
  return newDoc;
}

代码示例来源:origin: loklak/loklak_server

@Override
public BulkWriteResult writeEntries(List<Post> entries) throws IOException {
  List<BulkWriteEntry> jsonMapList = new ArrayList<BulkWriteEntry>();
  for (Post entry: entries) {
    this.objectCache.put(entry.getPostId(), entry);
    this.existCache.add(entry.getPostId());
    Map<String, Object> jsonMap = entry.toJSON().toMap();
    assert jsonMap != null;
    if (jsonMap == null) continue;
    BulkWriteEntry be = new BulkWriteEntry(
        entry.getPostId(), "local", "timestamp_id", null, jsonMap);
    jsonMapList.add(be);
  }
  if (jsonMapList.size() == 0) return ElasticsearchClient.EMPTY_BULK_RESULT;
  if (this.elasticsearch_client == null) return new BulkWriteResult();
  BulkWriteResult result = elasticsearch_client.writeMapBulk(this.index_name, jsonMapList);
  this.indexWrite.addAndGet(jsonMapList.size());
  return result;
}

代码示例来源:origin: loklak/loklak_server

if (queryList != null) for (QueryEntry t: queryList) queries.add(t.toJSON().toMap());

代码示例来源:origin: loklak/loklak_server

@Override
public BulkWriteResult writeEntries(Collection<IndexEntry<IndexObject>> entries) throws IOException {
  List<BulkWriteEntry> jsonMapList = new ArrayList<BulkWriteEntry>();
  for (IndexEntry<IndexObject> entry: entries) {
    this.objectCache.put(entry.getId(), entry.getObject());
    this.existCache.add(entry.getId());
    Map<String, Object> jsonMap = entry.getObject().toJSON().toMap();
    assert jsonMap != null;
    if (jsonMap == null) continue;
    BulkWriteEntry be = new BulkWriteEntry(entry.getId(), entry.getType().toString(), AbstractObjectEntry.TIMESTAMP_FIELDNAME, null, jsonMap);
    jsonMapList.add(be);
  }
  if (jsonMapList.size() == 0) return ElasticsearchClient.EMPTY_BULK_RESULT;
  if (this.elasticsearch_client == null) return new BulkWriteResult();
  BulkWriteResult result = this.elasticsearch_client.writeMapBulk(this.index_name, jsonMapList);
  this.indexWrite.addAndGet(jsonMapList.size());
  return result;
}

代码示例来源:origin: yacy/yacy_grid_mcp

public WebDocument(JSONObject obj) {
  super(obj.toMap());
}

代码示例来源:origin: yacy/yacy_grid_mcp

public Document(JSONObject obj) {
  super(obj.toMap());
}

代码示例来源:origin: yacy/yacy_grid_mcp

@Override
public IndexFactory add(String indexName, String typeName, String id, JSONObject object) throws IOException {
  ElasticIndexFactory.this.elasticsearchClient.writeMap(indexName, typeName, id, object.toMap());
  return ElasticIndexFactory.this;
}

代码示例来源:origin: b3log/latke

/**
 * Returns a java.util.List containing all of the elements in this array.
 * If an element in the array is a JSONArray or JSONObject it will also
 * be converted.
 * <p>
 * Warning: This method assumes that the data structure is acyclical.
 *
 * @return a java.util.List containing the elements of this array
 */
public List<Object> toList() {
  List<Object> results = new ArrayList<Object>(this.myArrayList.size());
  for (Object element : this.myArrayList) {
    if (element == null || JSONObject.NULL.equals(element)) {
      results.add(null);
    } else if (element instanceof JSONArray) {
      results.add(((JSONArray) element).toList());
    } else if (element instanceof JSONObject) {
      results.add(((JSONObject) element).toMap());
    } else {
      results.add(element);
    }
  }
  return results;
}

代码示例来源:origin: b3log/latke

/**
   * Returns a java.util.Map containing all of the entries in this object.
   * If an entry in the object is a JSONArray or JSONObject it will also
   * be converted.
   * <p>
   * Warning: This method assumes that the data structure is acyclical.
   *
   * @return a java.util.Map containing the entries of this object
   */
  public Map<String, Object> toMap() {
    Map<String, Object> results = new HashMap<String, Object>();
    for (Entry<String, Object> entry : this.entrySet()) {
      Object value;
      if (entry.getValue() == null || NULL.equals(entry.getValue())) {
        value = null;
      } else if (entry.getValue() instanceof JSONObject) {
        value = ((JSONObject) entry.getValue()).toMap();
      } else if (entry.getValue() instanceof JSONArray) {
        value = ((JSONArray) entry.getValue()).toList();
      } else {
        value = entry.getValue();
      }
      results.put(entry.getKey(), value);
    }
    return results;
  }
}

代码示例来源:origin: DV8FromTheWorld/JDA

public AuditLogChange createAuditLogChange(JSONObject change)
{
  final String key = change.getString("key");
  Object oldValue = change.isNull("old_value") ? null : change.get("old_value");
  Object newValue = change.isNull("new_value") ? null : change.get("new_value");
  // Don't confront users with JSON
  if (oldValue instanceof JSONArray || newValue instanceof JSONArray)
  {
    oldValue = oldValue instanceof JSONArray ? ((JSONArray) oldValue).toList() : oldValue;
    newValue = newValue instanceof JSONArray ? ((JSONArray) newValue).toList() : newValue;
  }
  else if (oldValue instanceof JSONObject || newValue instanceof JSONObject)
  {
    oldValue = oldValue instanceof JSONObject ? ((JSONObject) oldValue).toMap() : oldValue;
    newValue = newValue instanceof JSONObject ? ((JSONObject) newValue).toMap() : newValue;
  }
  return new AuditLogChange(oldValue, newValue, key);
}

代码示例来源:origin: DV8FromTheWorld/JDA

? new CaseInsensitiveMap<>(options.toMap()) : null;

代码示例来源:origin: yacy/yacy_grid_mcp

String url = json.getString(WebMapping.url_s.getMapping().name());
String urlid = MultiProtocolURL.getDigest(url);
boolean created = Data.gridIndex.getElasticClient().writeMap("web", "crawler", urlid, json.toMap());
Data.logger.info("MCP.processAction indexed " + ((line + 1)/2)  + "/" + jsonlist.length()/2 + "(" + (created ? "created" : "updated")+ "): " + url);

代码示例来源:origin: com.github.everit-org.json-schema/org.everit.json.schema

public SchemaLoaderBuilder schemaJson(Object schema) {
  if (schema instanceof JSONObject) {
    schema = (((JSONObject) schema).toMap());
  }
  this.schemaJson = schema;
  return this;
}

代码示例来源:origin: com.github.everit-org.json-schema/org.everit.json.schema

/**
 * Underscore-like extend function. Merges the properties of {@code additional} and
 * {@code original}. Neither {@code additional} nor {@code original} will be modified, but the
 * returned object may be referentially the same as one of the parameters (in case the other
 * parameter is an empty object).
 */
@Deprecated
static JSONObject extend(final JSONObject additional, final JSONObject original) {
  return new JSONObject(extend(additional.toMap(), original.toMap()));
}

代码示例来源:origin: com.github.everit-org.json-schema/org.everit.json.schema

static Object toJavaValue(Object orig) {
  if (orig instanceof JSONArray) {
    return ((JSONArray) orig).toList();
  } else if (orig instanceof JSONObject) {
    return ((JSONObject) orig).toMap();
  } else {
    return orig;
  }
}

代码示例来源:origin: io.github.javaeden.orchid/OrchidCore

@Override
  public Object execute(FunctionRequest request) {

    List<Object> fnParams = request.maximumNumberOfArguments(2)
                    .minimumNumberOfArguments(2)
                    .getArguments();

    String text = fnParams.get(0).toString();
    String extension = fnParams.get(1).toString();

    return context.compile(extension, text, new JSONObject(context.getOptionsData().toMap()));
  }
}

相关文章

JSONObject类方法