The above message is part of my JSON response, I would like to access the part that show 'Email is already taken' but I could not even though I have tried many different methods.
I am not familiar with JSON so I would like to ask everyone how can I finish this task.
Thanks.
--
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/d93240dc-88c0-4c61-8db7-180981758983o%40googlegroups.com.
final responseData = json.decode(response.body);
final String errorMsg = responseData['message'];print(errorMsg);And this is the error that I got:Unhandled Exception: type 'List<dynamic>' is not a subtype of type 'String'
Map<String, dynamic> data = responseData['message'];
is that how I should set it up
You need to declare it in a map and you will be able to fetch that message by using message as a key.
On Tue, Aug 11, 2020 at 5:47 PM Ximui <luumai...@gmail.com> wrote:
[{messages: [{id: Auth.form.error.email.taken, message: Email is already taken.}]}]
The above message is part of my JSON response, I would like to access the part that show 'Email is already taken' but I could not even though I have tried many different methods.
I am not familiar with JSON so I would like to ask everyone how can I finish this task.
Thanks.
--
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 flutt...@googlegroups.com.
--
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/53656a06-f71c-47f3-9274-e106e82d937do%40googlegroups.com.
Add a breakpoint to the second line. Use the debugger to understand the structure of responseData when your code hits the breakpoint. As per the error message, you’ll see its “message” field is not a String but a List.
On Tue, Aug 11, 2020 at 19:18 Ximui <luumai...@gmail.com> wrote:
Here is the code--final responseData = json.decode(response.body);final String errorMsg = responseData['message'];print(errorMsg);And this is the error that I got:Unhandled Exception: type 'List<dynamic>' is not a subtype of type 'String'
On Tuesday, August 11, 2020 at 3:47:47 PM UTC-7, Ximui wrote:[{messages: [{id: Auth.form.error.email.taken, message: Email is already taken.}]}]The above message is part of my JSON response, I would like to access the part that show 'Email is already taken' but I could not even though I have tried many different methods.
I am not familiar with JSON so I would like to ask everyone how can I finish this task.
Thanks.
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 flutt...@googlegroups.com.
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/ab601b17-360a-402b-b265-a3d293f19ccao%40googlegroups.com.
--
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/d93240dc-88c0-4c61-8db7-180981758983o%40googlegroups.com.
Map<String, dynamic> data = responseData['message'].first;
print(data);
List<dynamic> data1 = data[0];
print(data1);
I/flutter (27822): {messages: [{id: Auth.form.error.email.taken, message: Email is already taken.}]}
I/flutter (27822): null
I do not understand why data1 = data[0] return null. should it return id: ..., message: ... ?
--
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/749b4c25-8e4b-4053-a47c-0fd3a8e9c4a3o%40googlegroups.com.
--
I/flutter (31409): {messages: [{id: Auth.form.error.email.taken, message: Email is already taken.}]}Sorry for the late responses, the above is what I get fromhttp.Response response = await http.post('http://10.0.2.2:1337/auth/local/register', body: {
"username": _username,
"email": _email,
"password": _password
});final responseData = json.decode(response.body);
Map<String, dynamic> data = responseData['message'].first;
print(data);
And I tried to get the message 'Email is already taken' part and display it in my page.I understand that what I got back is a map with a list then a map inside of it.So I triedprint(data[0]['message'][0]['message']);print(data['message'][0]['message']);I both got:[ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: NoSuchMethodError: The method '[]' was called on null.I have been playing with it for a while still cannot figure it out
On Wednesday, August 12, 2020 at 5:33:43 PM UTC-7 souvik...@gmail.com wrote:
To view this discussion on the web visit https://groups.google.com/d/msgid/flutter-dev/5a7da608-524e-4619-86ed-7fb1623c7d89n%40googlegroups.com.