Ichigor
Hi!
I'm listening to a specific document:
TypeScript
final realtime = Realtime(client);
final subscription = realtime.subscribe([
'databases.64046c8b50eba8c807d0.collections.6405162fd68c7c61df67.documents.642a0de5238de5eb9e3a'
]);
subscription.stream.listen((response) {
// A callback will be made on changes for documents A and all files.
String jsonString = '${response.payload}';
print(jsonString);
});
and I get JSON like this:
TypeScript
{ first_name: Badma, userId: 642a0de3d38b4848156571, scores: 7, progress: 0.0001, errors: [], alchiki: 20, createdAt: 2023-04-03T02:21:08.785+00:00, friends: [6411842dda40129372d1, 6410dbd3bf73ca111c18], refcode: D9QSY, resultCheckRefered: null, userRefer: mqB8o, checkRefered: 2, image: null, $id: 642a0de5238de5eb9e3a, $createdAt: 2023-04-02T23:21:09 145+00:00, $updatedAt: 2023-05-02T09:48:37.380+00:00, $permissions: [read("user:642a0de3d38b48156571"), update("user:642a0de3d38b48156571"), delete("user:642a0de3d38b48156571")], $collectionId: 6405162fd68c7c61df67, $databaseId: 64046c8b50eba8c807d0}
When I try to execute:
TypeScript
subscription.stream.listen((response) {
// The callback will be executed on changes for document A and all files.
String jsonString = '${response.payload}';
Map<String, dynamic> data = jsonDecode(jsonString);
int scores = data['scores'];
print(scores);
});```
and get the scores data, the application crashes with an error:
see screen
what am I doing wrong?
TL;DR
The user is experiencing an issue when trying to retrieve data from a received JSON format using the `jsonDecode` function. They receive an error and are unsure what they are doing wrong.
The solution is to note that `response.payload` is already a `Map<String, Dynamic>`, so there is no need to use `jsonDecode` on it. They can directly access the values in `response.payload` using the appropriate keys. Maniac_Fighter
response.payload
is already a Map<String,Dynamic>. JsonDecode is not required here
Recommended threads
- Apple OAuth Scopes
Hi Hi, I've configured sign in with apple and this is the response i'm getting from apple once i've signed in. I cant find anywhere I set scopes. I remember se...
- Sign In With Apple OAuth Help
Hi All! I've got a flutter & appwrite app which Im trying to use sign in with apple for. I already have sign in with google working and the function is the sam...
- [SOLVED] OAuth With Google & Flutter
Hi all, I'm trying to sign in with google and it all goes swimmingly until the call back. I get a new user created on the appwrite dashboard however the flutte...