Android的,使用Javascript,犀牛,JSON犀牛、Android、Javascript、JSON

2023-09-07 09:00:50 作者:飞烟轻若梦

在回购中的文件夹漫长的寻找,我发现rhino1_7R2.jar为Android在的 HTTP://$c$c.google.com/p/android-scripting/source/browse/rhino/rhino1_7R2.jar 可惜1_7R3是不存在的。

After long search in repo folders I found rhino1_7R2.jar for Android at http://code.google.com/p/android-scripting/source/browse/rhino/rhino1_7R2.jar Unfortunately 1_7R3 is not there.

我使用用途JSON.stringify功能的脚本这是不是在1_7R2 present。有犀牛的JSON2.js文件,但我不知道在运行时加载它的正确方法。文档和示例codeS薄弱。我应该载入它作为运行的脚本中的字符串和prePEND?或者有更好的办法?

The script I'm using uses JSON.stringify function which is not present in 1_7R2. There is the JSON2.js file for Rhino but I don't know the proper way to load it at run time. Documentation and example codes are weak. Should I load it as a string and prepend on the running script? Or there is a better way?

我在使用JavaScript动态评估在一个循环中一些计算。我真的想避免prepending我每次调用javascript函数的时间JSON2.js。花了差不多一天发现犀牛已经支持JSON对象,在后期的版本,没有人费心将它移植到Android。看起来缺乏支持,另一个开源项目。

I'm using JavaScript to dynamically evaluate some calculations in a loop. I really want to avoid prepending the JSON2.js every time I call a javascript function. Spent almost one day to find out Rhino has supported JSON object at late version and nobody bothered to port it to Android. Looks like another open source project lacking support.

我应该放弃,并考虑使用的WebView方法?任何想法?

Should i give up and consider using WebView method? Any ideas?

推荐答案

据我了解,你哈瓦您希望通过犀牛运行一些JavaScript脚本。如果要加载另一个JavaScript文件,你可以使用负荷功能:

As I understand, you hava some JavaScript script that you want to run by Rhino. If you want to load another JavaScript file, you can use load function:

load("/your/path/json2.js");

在调用脚本可以使用json2库。

After that call your script can use json2 library.

var testStr = '{"test" : {"a": "aval", "b" : "bval"}}';
var jsonObj = JSON.parse(testStr);
var a = jsonObj.test.a;
 
精彩推荐
图片推荐