com.yworks.yfiles.server.tiles.support
Class JSONStringBuilder

java.lang.Object
  extended bycom.yworks.yfiles.server.tiles.support.JSONStringBuilder

public class JSONStringBuilder
extends Object

This class can be used to build a string which represents an object in JSON format. There are several addMember methods for adding members of different types. getJSONString() returns a JSON string containing all the members which were added before.

See Also:
JSON Spec

Constructor Summary
JSONStringBuilder()
          creates a new instance representing an empty JSON object.
 
Method Summary
 void addMember(String key, boolean value)
          adds a new member with a boolean value to the object represented by the string available via getJSONString().
 void addMember(String key, double value)
          adds a new member with a double value to the object represented by the string available via getJSONString().
 void addMember(String key, int value)
          adds a new member with an integer value to the object represented by the string available via getJSONString().
 void addMember(String key, Rectangle value)
          adds a new member with a rectangle value to the object represented by the string available via getJSONString().
 void addMember(String key, String value)
          performs addMember(key, value, true, true).
 void addMember(String key, String value, boolean escapeString, boolean addQuotes)
          adds a member to the object represented by the string available via getJSONString().
 void addMember(String key, YPoint value)
          adds a new member with a point value to the object represented by the string available via getJSONString().
 String getJSONString()
          returns the string in JSON format for an object with all the members added by addMember calls.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JSONStringBuilder

public JSONStringBuilder()
creates a new instance representing an empty JSON object.

Method Detail

addMember

public void addMember(String key,
                      String value,
                      boolean escapeString,
                      boolean addQuotes)
adds a member to the object represented by the string available via getJSONString(). Whether the string value of the member gets escaped and/or quoted is configurable. If a member for the same key has been added before it gets overridden. The key string gets escaped in any case.

Parameters:
key - the key for the new member
value - the value for the new member
escapeString - whether to escape the value
addQuotes - whether to add quotes to the value
See Also:
JSONSupport.escapeString(String), JSONSupport.escapeStringNoQuotes(String)

addMember

public void addMember(String key,
                      String value)
performs addMember(key, value, true, true).

Parameters:
key - the key for the new member
value - the value for the new member
See Also:
addMember(String, String, boolean, boolean)

addMember

public void addMember(String key,
                      Rectangle value)
adds a new member with a rectangle value to the object represented by the string available via getJSONString(). The string for the value is constructed using JSONSupport.rectangleString(Rectangle). The key string gets escaped.

Parameters:
key - the key for the new member
value - the rectangle value

addMember

public void addMember(String key,
                      YPoint value)
adds a new member with a point value to the object represented by the string available via getJSONString(). The string for the value is constructed using JSONSupport.pointString(YPoint). The key string gets escaped.

Parameters:
key - the key for the new member
value - the point value

addMember

public void addMember(String key,
                      boolean value)
adds a new member with a boolean value to the object represented by the string available via getJSONString(). The key string gets escaped.

Parameters:
key - the key for the new member
value - the value

addMember

public void addMember(String key,
                      int value)
adds a new member with an integer value to the object represented by the string available via getJSONString(). The key string gets escaped.

Parameters:
key - the key for the new member
value - the value

addMember

public void addMember(String key,
                      double value)
adds a new member with a double value to the object represented by the string available via getJSONString(). The key string gets escaped.

Parameters:
key - the key for the new member
value - the value

getJSONString

public String getJSONString()
returns the string in JSON format for an object with all the members added by addMember calls.

Returns:
a JSON string


Copyright © 2006-2013 yWorks GmbH. All rights reserved