Client and backend. This class is shared: the same code is compiled into your app and into your server, so everything on this page works in both.
public final class LevelJson
- Object
- LevelJson
A small JSON reader and writer for level files, shared by the app and the server.
Parsing is com.codename1.io.JSONParser’s, with one difference: numbers are
read from their text straight into fixed point (Fx#parse) as Integers,
never through double, so "speed": 1.5 means exactly the same thing on
every runtime – the server replays a run with these values and must reach
the hash the device did. Objects become Map (in document order), arrays
List, and true, false and null what one would expect.
Methods
Inherited methods
Method details
parse
public static Object parse(String text)Parses JSON text.
Parameters
textString- the JSON
Returns
a
Map for an object, a List for an arrayThrows
IllegalArgumentException- when the text is neither, or a number is out of fixed-point range
quote
public static void quote(StringBuilder sb, String s)Writes a JSON string literal.
Parameters
sbStringBuilder- the output
sString- the string
fx
public static int fx(Map<String, Object> m, String key, int def)A number field as fixed point.
Parameters
mMap<String, Object>- the object
keyString- the field
defint- the value when absent, fixed point
Returns
the field, fixed point
integer
public static int integer(Map<String, Object> m, String key, int def)A number field as a whole number (the fixed-point value floored).
Parameters
mMap<String, Object>- the object
keyString- the field
defint- the value when absent
Returns
the field
str
public static String str(Map<String, Object> m, String key, String def)A string field.
Parameters
mMap<String, Object>- the object
keyString- the field
defString- the value when absent
Returns
the field
obj
public static Map<String, Object> obj(Map<String, Object> m, String key)An object field.
Parameters
mMap<String, Object>- the object
keyString- the field
Returns
the nested object, or null
list
public static List<Object> list(Map<String, Object> m, String key)An array field.
Parameters
mMap<String, Object>- the object
keyString- the field
Returns
the list, or an empty list