I'm not a PHP developer but echo json_encode($arr_final) sounds like it
converts an Array (aka List) to a JSON string and converting an Array
means you get an Array. IF you want to get a Map you need to create and
convert a Map on PHP side too.
Ralph
Am 12.06.19 um 16:01 schrieb Pascal Fournier:
> Hello to all,
>
> i can't understand why my response.body from a http.get(url) return a
> List and not a Map....
>
> I call my backend with http.get(url) then my php code return this :
>
>
> php code ..........
> $arr_final = array();
> $arr = array ();
>
> // Query my database
> while($row=$sql_res->fetch_assoc())
> {
> $arr['city'] = $row["city"];
> $arr['country'] = $row["country"];
> array_push($arr_final,$arr);
> }
> echo json_encode($arr_final);
>
>
> To get the response in Flutter i did :
>
> List<dynamic> list=[];
>
> if (response.statusCode ==200) {
> print(json.decode(response.body));
> list= json.decode(response.body);
> }
>
>
>
> This way... it works.
>
> I thought that json return Map....
> here is a print of my response.body :
>
> *
> |
> [{city:Montréal,country:Canada},{city:Paris,country:France}]
> |
>
> *
>
> So why it is a List and not a List of Maps ??? because when it'S in
> curly braces {} it's a map... no?
>
> thanks a lot !
>
> Pascal
>
> --
> 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
> <mailto:
flutter-dev...@googlegroups.com>.
> To view this discussion on the web visit
>
https://groups.google.com/d/msgid/flutter-dev/b5216e94-3936-45fe-ba1f-f9eb2268c31b%40googlegroups.com
> <
https://groups.google.com/d/msgid/flutter-dev/b5216e94-3936-45fe-ba1f-f9eb2268c31b%40googlegroups.com?utm_medium=email&utm_source=footer>.