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

JsCallback.apply(String对象)出错 #11

Open
LiJia92 opened this issue Jan 13, 2016 · 0 comments
Open

JsCallback.apply(String对象)出错 #11

LiJia92 opened this issue Jan 13, 2016 · 0 comments

Comments

@LiJia92
Copy link

LiJia92 commented Jan 13, 2016

Log:I/chromium: [INFO:CONSOLE(1)] "Uncaught SyntaxError: Unexpected identifier", source: (1)。
我在调用jsCallback.apply()时,传入一个String对象,在apply方法里,有这样的代码:

StringBuilder sb = new StringBuilder();
for (Object arg : args){
    sb.append(",");
    boolean isStrArg = arg instanceof String;
    if (isStrArg) {
        sb.append("\"");
    }
    sb.append(String.valueOf(arg));
    if (isStrArg) {
        sb.append("\"");
    }
}

此方法会在参数首尾加上双引号。此时当传入的String对象包含双引号时(JSONObject.toString()方法生成的String对象就会包含双引号),就会出错。不包含则不会出现问题。
将append里面的双引号改成单引号能解决此问题。但是如果String对象包含单引号就又会导致这个问题了- -
延伸到既包含双引号又包含单引号的String对象又该如何传递呢?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant