evaluateJavaScript 执行结果中有乱码
cs-robert opened this issue · 4 comments
描述
Hummer version:
master 分支源码依赖
复现步骤
设备 samsung-G532F,android 系统版本 5.0
1.执行js逻辑
2.结果中出现乱码
预期结果
结果正常
样例代码、屏幕截图或者仓库链接
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main_home);
if (context == null) {
context = JSCContext.create();
((TextView) findViewById(R.id.info)).setText("context id is" + context.context);
}
findViewById(R.id.test).setOnClickListener(new View.OnClickListener() {
@OverRide
public void onClick(View view) {
try {
String js = readFileFromAssets(getApplicationContext(), "HelloWorld.js");
context.evaluateJavaScript(js);
} catch (Exception ex) {
Log.e(TAG, ex.getLocalizedMessage());
}
Object res = context.evaluateJavaScript("test()");
Log.i(TAG, "res is " + res);
((TextView) findViewById(R.id.res)).setText("context id is" + context.context + "\n" + res.toString());
}
});
}
public String readFileFromAssets(Context context, String fileName) throws IOException {
if (null == context || null == fileName) return null;
AssetManager am = context.getAssets();
InputStream input = am.open(fileName);
ByteArrayOutputStream output = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int len = 0;
while ((len = input.read(buffer)) != -1) {
output.write(buffer, 0, len);
}
output.close();
input.close();
return output.toString();
}
helloword.js
function test() {
let data = { "path": "/api/v4/recommend/recommend", "method": "GET", "params": ["bundle=daily_discover_main", "offset=0", "latitude=", "longitude=", "limit=20"] }
return JSON.stringify(data);
}
执行的是官方提供的HelloWorld.js吗?乱码具体是指哪个地方有乱码?(截图没太看明白)
HelloWorld.js是自己写的,只有一个test方法,返回一个stringify的json,这个json展示出来有乱码。截图的第三行开头
这个问题我这好像复现不了,你有其他类似的case出现吗?