-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Send data is a JSON string to js while happen error #6
Labels
Comments
i also came across this problem |
JSON.stringify() 兼容性有些问题。试试换 function o2s(object){ if(null==object)return "null"; var type = typeof object; if('object'== type){ if (Array == object.constructor) type = 'array'; else if (RegExp == object.constructor) type = 'regexp'; else type = 'object'; } switch(type){ case 'undefined': case 'unknown': return; break; case 'function': case 'boolean': case 'regexp': return object.toString(); break; case 'number': return isFinite(object) ? object.toString() : 'null'; break; case 'string': return '"' + object.replace(/(\\|\")/g,"\\$1").replace(/\n|\r|\t/g, function(){ var a = arguments[0]; return (a == '\n') ? '\\n': (a == '\r') ? '\\r': (a == '\t') ? '\\t': "" }) + '"'; break; case 'object': var pp="";var value =""; var results = []; try{ for (var property in object) { pp=object[property]; value = o2s(pp); if (value !== undefined) results.push('"'+property + '":' + value); }; } catch(e){ } return '{' + results.join(',') + '}'; break; case 'array': var results = []; if(object.length>=0){ for(var i = 0; i < object.length; i++){ var value = o2s(object[i]); if (value !== undefined) results.push(value); }; return '[' + results.join(',') + ']'; } else{ for(k in object) { var kk=k; var value = o2s(object[k]); if (value !== undefined) results.push('"'+kk+'":'+value); } return '{' + results.join(',') + '}'; } break; } } |
这个后来我是在 iframe.src 做了一次编码解决的,其中有些字符串没有做编码导致后边转码会失败的
|
我也遇到了同样的问题,这个bug有什么解决方案吗? @markzhai |
Open
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
when I call the Method
webView.callHandler(jsHandlerName, data, new CallBackFunction() {
@OverRide
public void onCallBack(String dataFromJS) { } });
and
data
is a json String as :{"misp_rate": 0.0, "miss_rate": 0.0, "reading_difficulty": 3, "sentence": "What's your name?", "sentscore": 7.729825044290912, "hypsent": "", "redu_rate": 100.0, "score": 0.0, "frame_stats": [{"end": 0.0, "fluency": "ok", "start": 0.0, "score": 0.0, "word": "WHAT'S", "class": "missing"}, {"end": 0.0, "fluency": "ok", "start": 0.0, "score": 0.0, "word": "YOUR", "class": "missing"}, {"end": 0.0, "fluency": "ok", "start": 0.0, "score": 0.0, "word": "NAME", "class": "missing"}], "result": [{"end": 0.0, "fluency": "ok", "start": 0.0, "score": 0.0, "word": "WHAT'S", "class": "missing"}, {"end": 0.0, "fluency": "ok", "start": 0.0, "score": 0.0, "word": "YOUR", "class": "missing"}, {"end": 0.0, "fluency": "ok", "start": 0.0, "score": 0.0, "word": "NAME", "class": "missing"}], "overall_score_grade": [1.0, 0.16716503179825531, 0.04837733590220021, 0.005763443891519606, 0.0009540585770522334, 6.666328219118981e-20, 0.0, 0.0, 0.0], "frames": 0.0, "vocal_score": 47.2583396248}
will happen a err:
07-06 11:22:17.740: I/chromium(12174): [INFO:CONSOLE(1)] "Uncaught SyntaxError: Unexpected identifier", source: (1)
The text was updated successfully, but these errors were encountered: