Package org.mozilla.javascript.json

Examples of org.mozilla.javascript.json.JsonParser


    return (String) NativeJSON.stringify(cx, scope, object, null, null);
  }

  public Object parse(String string) {
    try {
      return new JsonParser(cx, scope).parseValue(string);
    } catch (ParseException e) {
      e.printStackTrace();
    }
    // return (ScriptableObject) NativeJSON.parse(cx, scope, string, null);
    return string;
View Full Code Here


    private Context cx;

    @Before
    public void setUp() {
        cx = Context.enter();
        parser = new JsonParser(cx, cx.initStandardObjects());
    }
View Full Code Here

        }
    }

    private static Object parse(Context cx, Scriptable scope, String jtext) {
      try {
        return new JsonParser(cx, scope).parseValue(jtext);
      } catch (JsonParser.ParseException ex) {
        throw ScriptRuntime.constructError("SyntaxError", ex.getMessage());
      }
    }
View Full Code Here

    @Override
    public Object stringToJson(String json) {
        Context context = Context.getCurrentContext();
        try {
            return new JsonParser(context, ScriptRuntime.getGlobal(context)).parseValue(json);
        } catch (JsonParser.ParseException e) {
            logger.error("Unable to create a json object from string {}", json, e);
            throw new IllegalArgumentException(e.getMessage(), e);
        }
    }
View Full Code Here

    private Context cx;

    @Before
    public void setUp() {
        cx = Context.enter();
        parser = new JsonParser(cx, cx.initStandardObjects());
    }
View Full Code Here

        if (json == null) {
            throw ScriptRuntime.constructError("Error",
                    "The read function expects a single string argument");
        }
        Scriptable scope = funObj.getParentScope();
        JsonParser parser = new JsonParser(cx, scope);
        Object parsed;
        try {
            parsed = parser.parseValue(json);
        } catch (ParseException e) {
            throw ScriptRuntime.constructError("Error", e.getMessage());
        }
        Object result;
        if (parsed instanceof NativeObject) {
View Full Code Here

    Object xmlHttpRequest = new NativeJavaClass(global,
        XMLHttpRequest.class);
    global.put("XMLHttpRequest", global, xmlHttpRequest);
    new Console(global, "console");
    new Navigator(global, "navigator");
    jsonParser = new JsonParser(cx, global);
    String[] names = { "alert", "prompt", "confirm" };
    global.defineFunctionProperties(names, WebWrapper.class,
        ScriptableObject.DONTENUM);
  }
View Full Code Here

    private Context cx;

    @Before
    public void setUp() {
        cx = Context.enter();
        parser = new JsonParser(cx, cx.initStandardObjects());
    }
View Full Code Here

        }
    }

    private static Object parse(Context cx, Scriptable scope, String jtext) {
      try {
        return new JsonParser(cx, scope).parseValue(jtext);
      } catch (JsonParser.ParseException ex) {
        throw ScriptRuntime.constructError("SyntaxError", ex.getMessage());
      }
    }
View Full Code Here

        return findResource(moduleName + "/index", loaders, localPath);
    }

    private Scriptable parseJsonResource(Resource resource) throws IOException {
        JsonParser parser = new JsonParser(Context.getCurrentContext(), globalScope);
        try {
            Object result = parser.parseValue(resource.getContent());
            if (!(result instanceof Scriptable)) {
                throw new RuntimeException(
                        "Expected Object from package.json, got " + result);
            }
            return (Scriptable) result;
View Full Code Here

TOP

Related Classes of org.mozilla.javascript.json.JsonParser

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.