Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

evaluateJavaScript 执行结果中有乱码 #376

Open
cs-robert opened this issue Apr 6, 2022 · 4 comments
Open

evaluateJavaScript 执行结果中有乱码 #376

cs-robert opened this issue Apr 6, 2022 · 4 comments
Assignees
Labels
bug Something isn't working Platform: Android
Milestone

Comments

@cs-robert
Copy link

cs-robert commented Apr 6, 2022

描述

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

@cs-robert cs-robert added bug Something isn't working Needs: Triage 🔍 labels Apr 6, 2022
@bbssyyuui bbssyyuui self-assigned this Apr 6, 2022
@bbssyyuui bbssyyuui added this to the Android 0.4.5 milestone Apr 6, 2022
@bbssyyuui
Copy link
Collaborator

执行的是官方提供的HelloWorld.js吗?乱码具体是指哪个地方有乱码?(截图没太看明白)

@cs-robert
Copy link
Author

HelloWorld.js是自己写的,只有一个test方法,返回一个stringify的json,这个json展示出来有乱码。截图的第三行开头

@cs-robert
Copy link
Author

@cs-robert cs-robert reopened this Apr 6, 2022
@bbssyyuui
Copy link
Collaborator

这个问题我这好像复现不了,你有其他类似的case出现吗?

@bbssyyuui bbssyyuui modified the milestones: Android 0.4.5, Android 0.4.6 Mar 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Platform: Android
Projects
None yet
Development

No branches or pull requests

2 participants