evaluateJavaScript 执行结果中有乱码

Open
#376 4 comments 0 reactions 1 assignee View on GitHub

@bbssyyuui is already working on this.

Since Apr 6, 2022.

Assessment

This issue has not been assessed yet.

Description

bug Platform: Android

描述

master 分支
WX20220406-145406@2x

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);
}

Dominant language
Objective-C
Stars
1.4k
Forks
186
PR merge metrics
No merged PRs in 30d

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from didi/Hummer

All issues in didi/Hummer

Similar issues

More Objective-C issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.