zoukankan      html  css  js  c++  java
  • about script engine on jdk 6 is mozilla rhino

    http://java.sun.com/developer/technicalArticles/J2SE/Desktop/scripting/

    reference:

    here is an example

                String promotion_price = null;
                String json_string="var shopVipData={\"msg\":\"\",promo:[{\"type\":\"普通会员\",\"price\":\"45.75\"},{\"type\":\"高级会员\",\"price\":\"45.71\"},{\"type\":\"VIP会员\",\"price\":\"45.34\"},{\"type\":\"至尊VIP\",\"price\":\"44.88\"}]};";
                json_string=http_response;
                logger.debug(json_string);
                String js_string="var price;for(var i=0;i<=shopVipData.promo.length-1;i++){if(shopVipData.promo[i].type=='普通会员'){price=shopVipData.promo[i].price;}}";

                ScriptEngineManager manager = new ScriptEngineManager();
                ScriptEngine engine = manager.getEngineByName("JavaScript");
                Compilable compilable = (Compilable) engine;
                CompiledScript script = null;
                Bindings binds = engine.createBindings();
                try {
                    script = compilable.compile(json_string+js_string);
                    script.eval(binds);
                    promotion_price=binds.get("price").toString();
                    logger.debug("=-----------------------------");
                   
                } catch (ScriptException e) {
                    e.printStackTrace();
                }   

  • 相关阅读:
    Python--初识函数
    Python中的文件操作
    Python中的集合
    Python中的编码和解码
    Python的关键字is和==
    Python中的字典
    Python中的列表和元组
    Python中几种数据的常用内置方法
    Python的编码
    python_while
  • 原文地址:https://www.cnblogs.com/lexus/p/2336401.html
Copyright © 2011-2022 走看看