本文整理汇总了Java中jdk.nashorn.internal.parser.JSONParser.parse方法的典型用法代码示例。如果您正苦于以下问题:Java JSONParser.parse方法的具体用法?Java JSONParser.parse怎么用?Java JSONParser.parse使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类jdk.nashorn.internal.parser.JSONParser
的用法示例。
在下文中一共展示了JSONParser.parse方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
}