React-native android fetch 方法崩溃应用

React-native android fetch method crash app

我尝试卷曲我的 APIs :

curl http://localhost:8080/0/me -H "Authorization: xxx"

curl http://localhost:8080/0/me/contactlist -H "Authorization: xxx"

一切正常(都在 JSON Content-Length:1014 200OK 20ms 中响应)

但在 Genymotion 中,第一个 API 工作正常,第二个总是因错误而崩溃(不幸的是应用程序已停止):(

编辑:添加 logcat(抱歉,我忘了 adb logcat)

F/fbassert( 3233): Assert (/Users/mkonicek/code/react-native/ReactAndroid/src/main/jni/first-party/jni/LocalString.cpp:36): 4 byte utf-8 encodings only valid for up to 21 bits
F/libc    ( 3233): Fatal signal 11 (SIGSEGV), code 1, fault addr 0xdeadb00c in tid 3262 (imit=5&offset=1)
I/DEBUG   (   87): *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
I/DEBUG   (   87): Build fingerprint: 'generic/vbox86tp/vbox86tp:5.1/LMY47D/buildbot06101042:userdebug/test-keys'
I/DEBUG   (   87): Revision: '0'
I/DEBUG   (   87): ABI: 'x86'
I/DEBUG   (   87): pid: 3233, tid: 3262, name: imit=5&offset=1  >>> com.awesomeproject <<<
I/DEBUG   (   87): signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0xdeadb00c
I/DEBUG   (   87): Abort message: 'Assert (/Users/mkonicek/code/react-native/ReactAndroid/src/main/jni/first-party/jni/LocalString.cpp:36): 4 byte utf-8 encodings only valid for up to 21 bits'

好的,我刚知道一个问题

在 JSON 响应中有表情符号字符,当 js 尝试解码它时可能会导致问题。但是不知道为什么它不能被Promise捕获,太糟糕了。

解决方案:

服务器端 > 在编码前解析为 url 转义字符串 JSON

客户端 > 使用内置 decodeURI() 解析回值