pro*_*bie 5 android firebase google-cloud-functions
我尝试调用云函数并传递一些数据。我的数据是类型的,Map<String, Object>并且里面有一些嵌套的Map<String, Object>. 当试图用这个调用我的函数时:
getHttpsCallable(function).call(data)...
Run Code Online (Sandbox Code Playgroud)
我收到此错误:
Cloud Function Exception:
java.lang.IllegalArgumentException: Object cannot be encoded in JSON: [Ljava.util.Map;@42896770
at com.google.firebase.functions.Serializer.encode(Serializer.java:136)
at com.google.firebase.functions.Serializer.encode(Serializer.java:77)
at com.google.firebase.functions.FirebaseFunctions.call(FirebaseFunctions.java:255)
at com.google.firebase.functions.FirebaseFunctions.access$100(FirebaseFunctions.java:34)
at com.google.firebase.functions.FirebaseFunctions$2.then(FirebaseFunctions.java:233)
at com.google.firebase.functions.FirebaseFunctions$2.then(FirebaseFunctions.java:225)
at com.google.android.gms.tasks.zzd.run(Unknown Source)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:146)
at android.app.ActivityThread.main(ActivityThread.java:5653)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1291)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1107)
at dalvik.system.NativeStart.main(Native Method)
Run Code Online (Sandbox Code Playgroud)
打印我的数据对象时,它看起来像这样:
{items=[Ljava.util.Map;@42896770, element1=OzNGHzHeq6av03hRmMJ6, time=Sun May 05 04:40:00 MEZ 3918}
Run Code Online (Sandbox Code Playgroud)
我尝试了以下操作: 我尝试在我的数据对象中打包一个数组而不是一个 Map。=> 没用。
我试图自己将我的数据转换为 json 并发送它,这也不起作用。
我做了以下事情:
Gson gson = new Gson();
String dataJSON = gson.toJson(data);
Run Code Online (Sandbox Code Playgroud)
这导致了一个很好的格式化 JSON:
{"items":[{"count":1,"itemId":"94To3bKnxoWzayLdy55I"},{"count":3,"itemId":"fkNtIUxbfg5GhLJy2Dma"},{"count":1,"itemId":"sDYTp7cpQTRfWuI6CSaK"},{"count":1,"itemId":"qGGl5U0qihHnMzhBMjyb","options":["2.0","1.0","1.1","0.0"]},{"count":1,"itemId":"qGGl5U0qihHnMzhBMjyb","options":["2.0","1.0","1.1","0.1"]},{"count":1,"itemId":"qGGl5U0qihHnMzhBMjyb","options":["2.0","1.0","1.1","0.2"]},{"count":1,"itemId":"qGGl5U0qihHnMzhBMjyb","options":["2.3","1.0","1.1","0.1"]}],"storeId":"OzNGHzHeq6av03hRmMJ6","pickupTime":"May 5, 3918 4:40:00 AM"}
Run Code Online (Sandbox Code Playgroud)
但我也尝试使用硬编码的 JSON 调用我的函数,但它也不起作用。
我无法弄清楚我做错了什么。有人知道吗?
| 归档时间: |
|
| 查看次数: |
3258 次 |
| 最近记录: |