decode a String futter

21 views
Skip to first unread message

w.s...@gmail.com

unread,
Mar 6, 2021, 9:48:53 AM3/6/21
to Flutter Development (flutter-dev)

Why String can't decode back to Map after change to String?

FirebaseMessaging.onMessage.listen((RemoteMessage message) { print(message.data); var convertToString = (message.data).toString(); var map = jsonDecode(convertToString); });

Error

E/flutter (17220): [ERROR:flutter/lib/ui/ui_dart_state.cc(186)] Unhandled Exception: FormatException: Unexpected character (at character 2) E/flutter (17220): {notification_type: abc, ABC: {"assigned_to_id":null,"descri...

 Here my message data
{notification_type: abc, ABC: {...}, sound: default, body: ..., title: ...}

Suzuki Tomohiro

unread,
Mar 6, 2021, 12:22:17 PM3/6/21
to w.s...@gmail.com, Flutter Development (flutter-dev)
From the error message and the JSON example in the document below, I think you need to wrap the key with double quotes.


--
You received this message because you are subscribed to the Google Groups "Flutter Development (flutter-dev)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to flutter-dev...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/flutter-dev/c551e467-210b-4fa8-8a40-fba61b3cf224n%40googlegroups.com.

Tony Seng

unread,
Mar 6, 2021, 6:59:13 PM3/6/21
to Suzuki Tomohiro, Flutter Development (flutter-dev)
Thanks.I use jsonEncode instead of toString, it works now.
--
Whatever you are , be a good one.
Reply all
Reply to author
Forward
0 new messages