本文整理了Java中org.json.simple.JSONObject.toJSONString()
方法的一些代码示例,展示了JSONObject.toJSONString()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JSONObject.toJSONString()
方法的具体详情如下:
包路径:org.json.simple.JSONObject
类名称:JSONObject
方法名:toJSONString
[英]Convert a map to JSON text. The result is a JSON object. If this map is also a JSONAware, JSONAware specific behaviours will be omitted at this top level.
[中]将映射转换为JSON文本。结果是一个JSON对象。如果这个映射也是一个JSONAware,那么这个顶层将忽略特定于JSONAware的行为。
代码示例来源:origin: GlowstoneMC/Glowstone
/**
* Encode this chat message to its textual JSON representation.
*
* @return The encoded representation.
*/
public String encode() {
return object.toJSONString();
}
代码示例来源:origin: com.googlecode.json-simple/json-simple
public String toString(){
return toJSONString();
}
代码示例来源:origin: com.googlecode.json-simple/json-simple
public String toJSONString(){
return toJSONString(this);
}
代码示例来源:origin: GlowstoneMC/Glowstone
public StatusResponseMessage(JSONObject json) {
this.json = json.toJSONString();
}
代码示例来源:origin: com.googlecode.json-simple/json-simple
public static String toString(String key,Object value){
StringBuffer sb = new StringBuffer();
toJSONString(key, value, sb);
return sb.toString();
}
代码示例来源:origin: apache/storm
@Override
public byte[] mapRecord(Tuple 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/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: 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: 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: pentaho/pentaho-kettle
@GET
@Path( "/browse" )
@Produces( { APPLICATION_JSON } )
public Response browse() {
String path = "/";
try {
path = controller.browse();
} catch ( Exception e ) {
// Do nothing
}
JSONObject jsonObject = new JSONObject();
jsonObject.put( "path", path );
return Response.ok( jsonObject.toJSONString() ).build();
}
}
代码示例来源:origin: pentaho/pentaho-kettle
public String getCurrentUser() {
JSONObject jsonObject = new JSONObject();
jsonObject.put( "username", getPropsUI().getLastRepositoryLogin() );
return jsonObject.toJSONString();
}
代码示例来源:origin: shopizer-ecommerce/shopizer
@SuppressWarnings("unchecked")
public String toJSONString() {
JSONObject data = new JSONObject();
data.put("price", super.getPrice());
data.put("maximumWeight", this.getMaximumWeight());
return data.toJSONString();
}
代码示例来源:origin: shopizer-ecommerce/shopizer
@SuppressWarnings("unchecked")
@Override
public String toJSONString() {
JSONObject data = new JSONObject();
data.put("taxBasisCalculation", this.getTaxBasisCalculation().name());
return data.toJSONString();
}
代码示例来源:origin: apache/storm
public static String getJsonWithUpdatedResources(String jsonConf, Map<String, Double> resourceUpdates) {
try {
JSONParser parser = new JSONParser();
Object obj = parser.parse(jsonConf);
JSONObject jsonObject = (JSONObject) obj;
Map<String, Double> componentResourceMap =
(Map<String, Double>) jsonObject.getOrDefault(
Config.TOPOLOGY_COMPONENT_RESOURCES_MAP, new HashMap<String, Double>()
);
for (Map.Entry<String, Double> resourceUpdateEntry : resourceUpdates.entrySet()) {
if (NormalizedResources.RESOURCE_NAME_NORMALIZER.getResourceNameMapping().containsValue(resourceUpdateEntry.getKey())) {
// if there will be legacy values they will be in the outer conf
jsonObject.remove(getCorrespondingLegacyResourceName(resourceUpdateEntry.getKey()));
componentResourceMap.remove(getCorrespondingLegacyResourceName(resourceUpdateEntry.getKey()));
}
componentResourceMap.put(resourceUpdateEntry.getKey(), resourceUpdateEntry.getValue());
}
jsonObject.put(Config.TOPOLOGY_COMPONENT_RESOURCES_MAP, componentResourceMap);
return jsonObject.toJSONString();
} catch (ParseException ex) {
throw new RuntimeException("Failed to parse component resources with json: " + jsonConf);
}
}
代码示例来源:origin: shopizer-ecommerce/shopizer
@SuppressWarnings("unchecked")
@Override
public String toJSONString() {
JSONObject data = new JSONObject();
data.put("host", this.getHost());
data.put("port", this.getPort());
data.put("protocol", this.getProtocol());
data.put("username", this.getUsername());
data.put("smtpAuth", this.isSmtpAuth());
data.put("starttls", this.isStarttls());
data.put("password", this.getPassword());
return data.toJSONString();
}
代码示例来源:origin: GlowstoneMC/Glowstone
/**
* Writes the statistics of the player into its statistics file.
*
* @param player the player to write the statistics file from
*/
@Override
public void writeStatistics(GlowPlayer player) {
File file = getPlayerFile(player.getUniqueId());
StatisticMap map = player.getStatisticMap();
JSONObject json = new JSONObject(map.getValues());
try {
FileWriter writer = new FileWriter(file, false);
writer.write(json.toJSONString());
writer.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
代码示例来源:origin: pentaho/pentaho-kettle
public String createConnection() {
CompletableFuture<String> future = new CompletableFuture<>();
spoonSupplier.get().getShell().getDisplay().asyncExec( () -> {
DatabaseDialog databaseDialog = new DatabaseDialog( spoonSupplier.get().getShell(), new DatabaseMeta() );
databaseDialog.open();
DatabaseMeta databaseMeta = databaseDialog.getDatabaseMeta();
if ( databaseMeta != null ) {
if ( !isDatabaseWithNameExist( databaseMeta, true ) ) {
addDatabase( databaseMeta );
future.complete( databaseMeta.getName() );
} else {
DatabaseDialog.showDatabaseExistsDialog( spoonSupplier.get().getShell(), databaseMeta );
}
}
future.complete( "None" );
} );
JSONObject jsonObject = new JSONObject();
try {
jsonObject.put( "name", future.get() );
return jsonObject.toJSONString();
} catch ( Exception e ) {
jsonObject.put( "name", "None" );
return jsonObject.toJSONString();
}
}
代码示例来源:origin: pentaho/pentaho-kettle
public String editDatabaseConnection( String database ) {
CompletableFuture<String> future = new CompletableFuture<>();
spoonSupplier.get().getShell().getDisplay().asyncExec( () -> {
DatabaseMeta databaseMeta = getDatabase( database );
String originalName = databaseMeta.getName();
DatabaseDialog databaseDialog = new DatabaseDialog( spoonSupplier.get().getShell(), databaseMeta );
databaseDialog.open();
if ( !isDatabaseWithNameExist( databaseMeta, false ) ) {
save();
future.complete( databaseMeta.getName() );
} else {
DatabaseDialog.showDatabaseExistsDialog( spoonSupplier.get().getShell(), databaseMeta );
databaseMeta.setName( originalName );
databaseMeta.setDisplayName( originalName );
future.complete( originalName );
}
} );
JSONObject jsonObject = new JSONObject();
try {
jsonObject.put( "name", future.get() );
return jsonObject.toJSONString();
} catch ( Exception e ) {
jsonObject.put( "name", "None" );
return jsonObject.toJSONString();
}
}
代码示例来源:origin: shopizer-ecommerce/shopizer
@SuppressWarnings("unchecked")
@Override
public String toJSONString() {
JSONObject data = new JSONObject();
data.put("shipBaseType", this.getShippingBasisType().name());
data.put("shipOptionPriceType", this.getShippingOptionPriceType().name());
data.put("shipType", this.getShippingType().name());
data.put("shipPackageType", this.getShippingPackageType().name());
if(shipFreeType!=null) {
data.put("shipFreeType", this.getFreeShippingType().name());
}
data.put("shipDescription", this.getShippingDescription().name());
data.put("boxWidth", this.getBoxWidth());
data.put("boxHeight", this.getBoxHeight());
data.put("boxLength", this.getBoxLength());
data.put("boxWeight", this.getBoxWeight());
data.put("maxWeight", this.getMaxWeight());
data.put("freeShippingEnabled", this.freeShippingEnabled);
data.put("orderTotalFreeShipping", this.orderTotalFreeShipping);
data.put("handlingFees", this.handlingFees);
data.put("taxOnShipping", this.taxOnShipping);
return data.toJSONString();
}
代码示例来源: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;
}
内容来源于网络,如有侵权,请联系作者删除!