本文整理汇总了Java中jdk.nashorn.internal.parser.JSONParser类的典型用法代码示例。如果您正苦于以下问题:Java JSONParser类的具体用法?Java JSONParser怎么用?Java JSONParser使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
JSONParser类属于jdk.nashorn.internal.parser包,在下文中一共展示了JSONParser类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: parse
import jdk.nashorn.internal.parser.JSONParser; //导入依赖的package包/类
/**
* Parses the given JSON text string and returns object representation.
*
* @param text JSON text to be parsed
* @param reviver optional value: function that takes two parameters (key, value)
* @return Object representation of JSON text given
*/
public static Object parse(final Object text, final Object reviver) {
final String str = JSType.toString(text);
final Global global = Context.getGlobal();
final boolean dualFields = ((ScriptObject) global).useDualFields();
final JSONParser parser = new JSONParser(str, global, dualFields);
final Object value;
try {
value = parser.parse();
} catch (final ParserException e) {
throw ECMAErrors.syntaxError(e, "invalid.json", e.getMessage());
}
return applyReviver(global, value, reviver);
}
示例2: parse
import jdk.nashorn.internal.parser.JSONParser; //导入依赖的package包/类
/**
* Parses the given JSON text string and returns object representation.
*
* @param text JSON text to be parsed
* @param reviver optional value: function that takes two parameters (key, value)
* @return Object representation of JSON text given
*/
public static Object parse(final Object text, final Object reviver) {
final String str = JSType.toString(text);
final JSONParser parser = new JSONParser(sourceFor("<json>", str), new Context.ThrowErrorManager());
Node node;
try {
node = parser.parse();
} catch (final ParserException e) {
throw ECMAErrors.syntaxError(e, "invalid.json", e.getMessage());
}
final Global global = Context.getGlobal();
final Object unfiltered = convertNode(global, node);
return applyReviver(global, unfiltered, reviver);
}
示例3: parse
import jdk.nashorn.internal.parser.JSONParser; //导入依赖的package包/类
/**
* Parses the given JSON text string and returns object representation.
*
* @param text JSON text to be parsed
* @param reviver optional value: function that takes two parameters (key, value)
* @return Object representation of JSON text given
*/
public static Object parse(final Object text, final Object reviver) {
final String str = JSType.toString(text);
final JSONParser parser = new JSONParser(
new Source("<json>", str),
new Context.ThrowErrorManager());
Node node;
try {
node = parser.parse();
} catch (final ParserException e) {
throw ECMAErrors.syntaxError(e, "invalid.json", e.getMessage());
}
final ScriptObject global = Context.getGlobalTrusted();
Object unfiltered = convertNode(global, node);
return applyReviver(global, unfiltered, reviver);
}
示例4: quote
import jdk.nashorn.internal.parser.JSONParser; //导入依赖的package包/类
private static String quote(final String str) {
return JSONParser.quote(str);
}
示例5: quote
import jdk.nashorn.internal.parser.JSONParser; //导入依赖的package包/类
/**
* Returns JSON-compatible quoted version of the given string.
*
* @param str String to be quoted
* @return JSON-compatible quoted string
*/
public static String quote(final String str) {
return JSONParser.quote(str);
}