
javajs.util.JSJSONParser Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jmol Show documentation
Show all versions of jmol Show documentation
Jmol: an open-source Java viewer for chemical structures in 3D
package javajs.util;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.Map;
import javajs.J2SIgnoreImport;
/**
* a very simple JSON parser for JSON objects that are compatible with JavaScript
* A gross simplification of https://github.com/douglascrockford/JSON-java
*
* A SUBSET of JSON with similarly to window.JSON.parse():
*
* In JavaScript returns "null" for a null value, not null
*
* -- requires quoted strings for keys and values
*
* -- does not allow /xxx/ objects
*
* @author Bob Hanson
*
*/
@J2SIgnoreImport({ HashMap.class })
public class JSJSONParser {
private String str;
private int index;
private int len;
private boolean asHashTable;
public JSJSONParser () {
// for reflection
}
/**
* requires { "key":"value", "key":"value",....}
*
* @param str
* @param asHashTable TODO
*
* @return Map or null
*/
@SuppressWarnings("unchecked")
public Map parseMap(String str, boolean asHashTable) {
index = 0;
this.asHashTable = asHashTable;
this.str = str;
len = str.length();
if (getChar() != '{')
return null;
returnChar();
return (Map) getValue(false);
}
/**
* Could return Integer, Float, Boolean, String, Map, Lst
© 2015 - 2025 Weber Informatics LLC | Privacy Policy