We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
master 分支
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); }
The text was updated successfully, but these errors were encountered:
执行的是官方提供的HelloWorld.js吗?乱码具体是指哪个地方有乱码?(截图没太看明白)
Sorry, something went wrong.
HelloWorld.js是自己写的,只有一个test方法,返回一个stringify的json,这个json展示出来有乱码。截图的第三行开头
这个问题我这好像复现不了,你有其他类似的case出现吗?
bbssyyuui
No branches or pull requests
描述
master 分支
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());
}
});
}
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);
}
The text was updated successfully, but these errors were encountered: