package Json import HashMap import LinkedList import public Scanner import public BigString import LZW import initlater JsonParser public constant JSON_SIGN_EQUAL = new Delimiter("=") public constant JSON_SIGN_COMMA = new Delimiter("_") public constant JSON_OPEN_BRACKET = new Delimiter("(") public constant JSON_CLOSE_BRACKET = new Delimiter(")") public constant JSON_OPEN_ARRAY = new Delimiter("[") public constant JSON_CLOSE_ARRAY = new Delimiter("]") public constant JSON_HEADER = new Delimiter("J") public class Property BigSubString name BigSubString value construct(BigSubString name, BigSubString value) this.name = name this.value = value construct(string name, string value) this.name = new BigSubString(name) this.value = new BigSubString(value) ondestroy if name.length >= 0 destroy name name = null if value.length >= 0 destroy value value = null public class Json HashMap properties = new HashMap() LinkedList plist = new LinkedList() function addProperty(Property p) if p.name != null and p.name.length >= 0 plist.add(p) p.name.next = null p.value.next = null properties.put(p.name.getSingle().getHash(), p) function getProperty(string key) returns Property return properties.get(key.getHash()) function getReal(string key) returns real return getInt(key).toReal() function getInt(string key) returns int let s = getString(key) if s == null or s.getSingleLength() == 0 return 0 let ss = s.getSingle() return ss.toInt() function getString(string key) returns BigSubString return properties.get(key.getHash()).value function getStringList(string key, JsonParser parser, PayloadCallback finalCallback) let str = getString(key) str.next = null finalCallback.customData = parser castTo int parser.setInput(new BigString()..addSubString(str)) if DEBUG_LEVEL == Loglevel.TRACE parser.bigInput.debugPrint() parser.parseList(finalCallback) function hasKey(string key) returns boolean let s = getString(key) return not (s == null or s.getSingleLength() == 0) function addToBigString(BigString big) returns BigString for p from plist.staticItr() big.addString(p.name.getSingle()) p.value.addToBigString(big) return big function reset() properties.flush() let itr = plist.staticItr() for _p from itr destroy itr.remove() ondestroy destroy properties for p from plist.staticItr() destroy p destroy plist