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

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

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

JSONObject.put介绍

暂无

代码示例

代码示例来源:origin: LawnchairLauncher/Lawnchair

@Override
public String toString() {
  // Create a new json object
  JSONObject obj = new JSONObject();
  obj.put("buildNumber", buildNumber);
  obj.put("download", download.toString());
  // Return parsed json to string
  return obj.toJSONString();
}

代码示例来源:origin: shopizer-ecommerce/shopizer

@SuppressWarnings("unchecked")
@Override
public String toJSONString() {
  JSONArray jsonArray = new JSONArray();
  for(String kw : keywords) {
    JSONObject data = new JSONObject();
    data.put("name", kw);
    data.put("value", kw);
    jsonArray.add(data);
  }
  return jsonArray.toJSONString();
}

代码示例来源:origin: alibaba/jstorm

public Number connect(Map conf, TopologyContext context) throws IOException, NoOutputException {
  JSONObject setupInfo = new JSONObject();
  setupInfo.put("pidDir", context.getPIDDir());
  setupInfo.put("conf", conf);
  setupInfo.put("context", context);
  writeMessage(setupInfo);
  return (Number) ((JSONObject) readMessage()).get("pid");
}

代码示例来源:origin: apache/metron

@SuppressWarnings("unchecked")
private void parseRBMMessage(JSONObject json) {
 String message = (String) json.get("message");
 if (message.contains("(")) {
  json.put("process", message.substring(0, message.indexOf("(")));
  if (message.contains(":")) {
   json.put("message", message.substring(message.indexOf(":") + 2));
  }
 }
}

代码示例来源:origin: pentaho/pentaho-kettle

public JSONArray storeRecentSearch( String recentSearch ) {
 JSONArray recentSearches = getRecentSearches();
 try {
  if ( recentSearch == null || recentSearches.contains( recentSearch ) ) {
   return recentSearches;
  }
  recentSearches.add( recentSearch );
  if ( recentSearches.size() > 5 ) {
   recentSearches.remove( 0 );
  }
  PropsUI props = PropsUI.getInstance();
  String jsonValue = props.getRecentSearches();
  JSONParser jsonParser = new JSONParser();
  JSONObject jsonObject = jsonValue != null ? (JSONObject) jsonParser.parse( jsonValue ) : new JSONObject();
  jsonObject.put( getLogin(), recentSearches );
  props.setRecentSearches( jsonObject.toJSONString() );
 } catch ( Exception e ) {
  e.printStackTrace();
 }
 return recentSearches;
}

代码示例来源:origin: rhuss/jolokia

/** {@inheritDoc} */
  @Override
  JSONObject toJson() {
    JSONObject ret = super.toJson();
    ret.put("operation",operation);
    if (arguments.size() > 0) {
      JSONArray args = new JSONArray();
      for (Object arg : arguments) {
        args.add(serializeArgumentToJson(arg));
      }
      ret.put("arguments",args);
    }
    return ret;
  }
}

代码示例来源:origin: apache/metron

@Override
public JSONObject joinMessages(Map<String, Tuple> streamMessageMap, MessageGetStrategy messageGetStrategy) {
 JSONObject message = new JSONObject();
 for (String key : streamMessageMap.keySet()) {
  Tuple tuple = streamMessageMap.get(key);
  JSONObject obj = (JSONObject) messageGetStrategy.get(tuple);
  message.putAll(obj);
 }
 List<Object> emptyKeys = new ArrayList<>();
 for(Object key : message.keySet()) {
  Object value = message.get(key);
  if(value == null || value.toString().length() == 0) {
   emptyKeys.add(key);
  }
 }
 for(Object o : emptyKeys) {
  message.remove(o);
 }
 message.put(getClass().getSimpleName().toLowerCase() + ".joiner.ts", "" + System.currentTimeMillis());
 return  message;
}

代码示例来源:origin: linkedin/indextank-engine

@SuppressWarnings("unchecked")
private void addResult(JSONArray ja, SearchResult result) {
  JSONObject document = new JSONObject();
  document.putAll(result.getFields());
  document.put("docid", result.getDocId());
  document.put("query_relevance_score", result.getScore());
  for(Entry<Integer, Double> entry: result.getVariables().entrySet()) {
    document.put("variable_" + entry.getKey(), entry.getValue());
  }
  for(Entry<String, String> entry: result.getCategories().entrySet()) {
    document.put("category_" + entry.getKey(), entry.getValue());
  }
  ja.add(document);
}

代码示例来源:origin: pentaho/pentaho-kettle

@SuppressWarnings( "unchecked" )
private void outPutRow( Object[] rowData ) throws KettleStepException {
 // We can now output an object
 data.jg = new JSONObject();
 data.jg.put( data.realBlocName, data.ja );
 String value = data.jg.toJSONString();
 if ( data.outputValue && data.outputRowMeta != null ) {
  Object[] outputRowData = RowDataUtil.addValueData( rowData, data.inputRowMetaSize, value );
  incrementLinesOutput();
  putRow( data.outputRowMeta, outputRowData );
 }
 if ( data.writeToFile && !data.ja.isEmpty() ) {
  // Open a file
  if ( !openNewFile() ) {
   throw new KettleStepException( BaseMessages.getString(
    PKG, "JsonOutput.Error.OpenNewFile", buildFilename() ) );
  }
  // Write data to file
  try {
   data.writer.write( value );
  } catch ( Exception e ) {
   throw new KettleStepException( BaseMessages.getString( PKG, "JsonOutput.Error.Writing" ), e );
  }
  // Close file
  closeFile();
 }
 // Data are safe
 data.rowsAreSafe = true;
 data.ja = new JSONArray();
}

代码示例来源:origin: apache/metron

@SuppressWarnings({"unchecked"})
public JSONObject getJSONObject() {
 JSONObject errorMessage = new JSONObject();
 errorMessage.put(Constants.GUID, UUID.randomUUID().toString());
 errorMessage.put(Constants.SENSOR_TYPE, "error");
 if (sensorTypes.size() == 1) {
  errorMessage.put(ErrorFields.FAILED_SENSOR_TYPE.getName(), sensorTypes.iterator().next());
 } else {
  errorMessage
    .put(ErrorFields.FAILED_SENSOR_TYPE.getName(), new JSONArray().addAll(sensorTypes));
 }
 errorMessage.put(ErrorFields.ERROR_TYPE.getName(), errorType.getType());
 addMessageString(errorMessage);
   addStacktrace(errorMessage);
 addTimestamp(errorMessage);
 addHostname(errorMessage);
 addRawMessages(errorMessage);
 addErrorHash(errorMessage);
 return errorMessage;
}

代码示例来源:origin: rhuss/jolokia

/** {@inheritDoc} */
@Override
JSONObject toJson() {
  JSONObject ret = super.toJson();
  if (hasSingleAttribute()) {
    ret.put("attribute",attributes.get(0));
  } else if (!hasAllAttributes()) {
    JSONArray attrs = new JSONArray();
    attrs.addAll(attributes);
    ret.put("attribute",attrs);
  }
  if (path != null) {
    ret.put("path",path);
  }
  return ret;
}

代码示例来源:origin: pentaho/pentaho-kettle

@SuppressWarnings( "unchecked" )
public String getPlugins() {
 List<PluginInterface> plugins = pluginRegistry.getPlugins( RepositoryPluginType.class );
 JSONArray list = new JSONArray();
 for ( PluginInterface pluginInterface : plugins ) {
  if ( !pluginInterface.getIds()[0].equals( "PentahoEnterpriseRepository" ) ) {
   JSONObject repoJSON = new JSONObject();
   repoJSON.put( "id", pluginInterface.getIds()[ 0 ] );
   repoJSON.put( "name", pluginInterface.getName() );
   repoJSON.put( "description", pluginInterface.getDescription() );
   list.add( repoJSON );
  }
 }
 return list.toString();
}

代码示例来源:origin: Vedenin/useful-java-links

public static void main(String[] args) {
    // convert Java to json
    JSONObject root = new JSONObject();
    root.put("message", "Hi");
    JSONObject place = new JSONObject();
    place.put("name", "World!");
    root.put("place", place);
    String json = root.toJSONString();
    System.out.println(json);

    System.out.println();
    // convert json to Java
    JSONObject obj = (JSONObject) JSONValue.parse(json);
    String message = (String) obj.get("message");
    place = (JSONObject) obj.get("place");
    String name = (String) place.get("name");
    System.out.println(message + " " + name);
  }
}

代码示例来源:origin: apache/storm

@Override
public byte[] mapRecord(TridentTuple tuple) {
  JSONObject obj = new JSONObject();
  if (this.columnFields != null) {
    for (String field : this.columnFields) {
      obj.put(field, tuple.getValueByField(field));
    }
  }
  return obj.toJSONString().getBytes();
}

代码示例来源:origin: apache/metron

@SuppressWarnings("unchecked")
 private void parseOtherMessage(JSONObject json) {
  String message = (String) json.get("message");
  if (message.contains("(")) {
   json.put("process", message.substring(0, message.indexOf("(")));
   if (message.contains(":")) {
    json.put("message", message.substring(message.indexOf(":") + 2));
   }
  }
 }
}

代码示例来源:origin: pentaho/pentaho-kettle

JSONObject jo = new JSONObject();
  jo.put( outputField.getElementName(), data.inputRowMeta.getBoolean( row, data.fieldIndexes[i] ) );
  break;
 case ValueMetaInterface.TYPE_INTEGER:
  jo.put( outputField.getElementName(), data.inputRowMeta.getInteger( row, data.fieldIndexes[i] ) );
  break;
 case ValueMetaInterface.TYPE_NUMBER:
  jo.put( outputField.getElementName(), data.inputRowMeta.getNumber( row, data.fieldIndexes[i] ) );
  break;
 case ValueMetaInterface.TYPE_BIGNUMBER:
  jo.put( outputField.getElementName(), data.inputRowMeta.getBigNumber( row, data.fieldIndexes[i] ) );
  break;
 default:
  jo.put( outputField.getElementName(), data.inputRowMeta.getString( row, data.fieldIndexes[i] ) );
  break;
data.ja.add( jo );

代码示例来源:origin: org.apache.clerezza/jaxrs.rdf.providers

private void createVariables(List<String> variables, JSONObject head) {
    JSONArray vars = null;
    for (String variable : variables) {
      if (vars == null) {
        vars = new JSONArray();
        head.put("vars", vars);
      }
      vars.add(variable);
    }
  }
}

代码示例来源:origin: Exslims/MercuryTrade

private void createEmptyFile() {
  try {
    FileWriter fileWriter = new FileWriter(HISTORY_FILE);
    JSONObject root = new JSONObject();
    root.put("messages", new JSONArray());
    fileWriter.write(root.toJSONString());
    fileWriter.flush();
    fileWriter.close();
  } catch (IOException e) {
    logger.error("Error during creating history file: ", e);
  }
}

代码示例来源:origin: shopizer-ecommerce/shopizer

JSONObject obj = new JSONObject();
obj.put("name", this.getName());
obj.put("price", this.getPrice());
obj.put("description", this.getDescription());
obj.put("highlight", this.getHighlight());
obj.put("store", this.getStore());
obj.put("manufacturer", this.getManufacturer());
obj.put("lang", this.getLang());
obj.put("id", this.getId());
if(categories!=null) {
  JSONArray categoriesArray = new JSONArray();
  for(String category : categories) {
    categoriesArray.add(category);
  obj.put("categories", categoriesArray);
  JSONArray tagsArray = new JSONArray();
  for(String tag : tags) {
    tagsArray.add(tag);
  obj.put("tags", tagsArray);

代码示例来源:origin: pentaho/pentaho-kettle

JSONObject json = new JSONObject();
for ( Header header : headers ) {
 Object previousValue = json.get( header.getName() );
 if ( previousValue == null ) {
  json.put( header.getName(), header.getValue() );
 } else if ( previousValue instanceof List ) {
  List<String> list = (List<String>) previousValue;
  list.add( (String) previousValue );
  list.add( header.getValue() );
  json.put( header.getName(), list );

相关文章