How Can I get a List object by HttpClientResponse?
How can I get a List object in "result"? I tried with toList() method on "request" object, but I can't solve this.
import 'dart:io';
import 'dart:convert';
void main() async {
var request = await HttpClient().getUrl(Uri.parse('https://jsonplaceholder.typicode.com/posts')); // produces a request object
var response = await request.close(); // sends the request
// transforms and prints the response
var result;
await for (var contents in response.transform(Utf8Decoder())) {
result =contents;
}
print(result);
}
Thanks,
Daniel
dart flutter
add a comment |
How can I get a List object in "result"? I tried with toList() method on "request" object, but I can't solve this.
import 'dart:io';
import 'dart:convert';
void main() async {
var request = await HttpClient().getUrl(Uri.parse('https://jsonplaceholder.typicode.com/posts')); // produces a request object
var response = await request.close(); // sends the request
// transforms and prints the response
var result;
await for (var contents in response.transform(Utf8Decoder())) {
result =contents;
}
print(result);
}
Thanks,
Daniel
dart flutter
add a comment |
How can I get a List object in "result"? I tried with toList() method on "request" object, but I can't solve this.
import 'dart:io';
import 'dart:convert';
void main() async {
var request = await HttpClient().getUrl(Uri.parse('https://jsonplaceholder.typicode.com/posts')); // produces a request object
var response = await request.close(); // sends the request
// transforms and prints the response
var result;
await for (var contents in response.transform(Utf8Decoder())) {
result =contents;
}
print(result);
}
Thanks,
Daniel
dart flutter
How can I get a List object in "result"? I tried with toList() method on "request" object, but I can't solve this.
import 'dart:io';
import 'dart:convert';
void main() async {
var request = await HttpClient().getUrl(Uri.parse('https://jsonplaceholder.typicode.com/posts')); // produces a request object
var response = await request.close(); // sends the request
// transforms and prints the response
var result;
await for (var contents in response.transform(Utf8Decoder())) {
result =contents;
}
print(result);
}
Thanks,
Daniel
dart flutter
dart flutter
asked Nov 24 '18 at 16:09
DomDunkDomDunk
23
23
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
Firstly, response.transform return multiple parts of result, you need to get all by joining them together:
var result = new StringBuffer();
await for (var contents in response.transform(Utf8Decoder())) {
result.write(contents);
}
Secondly, you result is just a "text" (in json format), not an "object" as you expect, you need to decode it:
List<dynamic> myList = jsonDecode(result.toString());
print(myList);
import 'dart:io'; import 'dart:convert'; void main() async { var request = await HttpClient().getUrl(Uri.parse('earthquake.usgs.gov/earthquakes/feed/v1.0/summary/…)); var response = await request.close(); // sends the request var result = new StringBuffer(); await for (var contents in response.transform(Utf8Decoder())) { result.write(contents); } List<dynamic> myList = jsonDecode(result.toString()); print(myList[0]['title']); }
– DomDunk
Nov 27 '18 at 12:41
Why does not it work?
– DomDunk
Nov 27 '18 at 12:42
I solved in this way:
– DomDunk
Nov 27 '18 at 18:00
'code' var myList = jsonDecode(result.toString()); List quakes = myList['features']; } 'code'
– DomDunk
Nov 27 '18 at 18:01
add a comment |
Simply the following
List elements = json.decode(response.body);
error: The getter 'body' isn't defined for the class 'HttpClientResponse'. (undefined_getter at [flutter_app] libmain.dart:40)
– DomDunk
Nov 27 '18 at 2:12
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53459989%2fhow-can-i-get-a-list-object-by-httpclientresponse%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Firstly, response.transform return multiple parts of result, you need to get all by joining them together:
var result = new StringBuffer();
await for (var contents in response.transform(Utf8Decoder())) {
result.write(contents);
}
Secondly, you result is just a "text" (in json format), not an "object" as you expect, you need to decode it:
List<dynamic> myList = jsonDecode(result.toString());
print(myList);
import 'dart:io'; import 'dart:convert'; void main() async { var request = await HttpClient().getUrl(Uri.parse('earthquake.usgs.gov/earthquakes/feed/v1.0/summary/…)); var response = await request.close(); // sends the request var result = new StringBuffer(); await for (var contents in response.transform(Utf8Decoder())) { result.write(contents); } List<dynamic> myList = jsonDecode(result.toString()); print(myList[0]['title']); }
– DomDunk
Nov 27 '18 at 12:41
Why does not it work?
– DomDunk
Nov 27 '18 at 12:42
I solved in this way:
– DomDunk
Nov 27 '18 at 18:00
'code' var myList = jsonDecode(result.toString()); List quakes = myList['features']; } 'code'
– DomDunk
Nov 27 '18 at 18:01
add a comment |
Firstly, response.transform return multiple parts of result, you need to get all by joining them together:
var result = new StringBuffer();
await for (var contents in response.transform(Utf8Decoder())) {
result.write(contents);
}
Secondly, you result is just a "text" (in json format), not an "object" as you expect, you need to decode it:
List<dynamic> myList = jsonDecode(result.toString());
print(myList);
import 'dart:io'; import 'dart:convert'; void main() async { var request = await HttpClient().getUrl(Uri.parse('earthquake.usgs.gov/earthquakes/feed/v1.0/summary/…)); var response = await request.close(); // sends the request var result = new StringBuffer(); await for (var contents in response.transform(Utf8Decoder())) { result.write(contents); } List<dynamic> myList = jsonDecode(result.toString()); print(myList[0]['title']); }
– DomDunk
Nov 27 '18 at 12:41
Why does not it work?
– DomDunk
Nov 27 '18 at 12:42
I solved in this way:
– DomDunk
Nov 27 '18 at 18:00
'code' var myList = jsonDecode(result.toString()); List quakes = myList['features']; } 'code'
– DomDunk
Nov 27 '18 at 18:01
add a comment |
Firstly, response.transform return multiple parts of result, you need to get all by joining them together:
var result = new StringBuffer();
await for (var contents in response.transform(Utf8Decoder())) {
result.write(contents);
}
Secondly, you result is just a "text" (in json format), not an "object" as you expect, you need to decode it:
List<dynamic> myList = jsonDecode(result.toString());
print(myList);
Firstly, response.transform return multiple parts of result, you need to get all by joining them together:
var result = new StringBuffer();
await for (var contents in response.transform(Utf8Decoder())) {
result.write(contents);
}
Secondly, you result is just a "text" (in json format), not an "object" as you expect, you need to decode it:
List<dynamic> myList = jsonDecode(result.toString());
print(myList);
answered Nov 24 '18 at 18:20
yelliveryelliver
2,54332152
2,54332152
import 'dart:io'; import 'dart:convert'; void main() async { var request = await HttpClient().getUrl(Uri.parse('earthquake.usgs.gov/earthquakes/feed/v1.0/summary/…)); var response = await request.close(); // sends the request var result = new StringBuffer(); await for (var contents in response.transform(Utf8Decoder())) { result.write(contents); } List<dynamic> myList = jsonDecode(result.toString()); print(myList[0]['title']); }
– DomDunk
Nov 27 '18 at 12:41
Why does not it work?
– DomDunk
Nov 27 '18 at 12:42
I solved in this way:
– DomDunk
Nov 27 '18 at 18:00
'code' var myList = jsonDecode(result.toString()); List quakes = myList['features']; } 'code'
– DomDunk
Nov 27 '18 at 18:01
add a comment |
import 'dart:io'; import 'dart:convert'; void main() async { var request = await HttpClient().getUrl(Uri.parse('earthquake.usgs.gov/earthquakes/feed/v1.0/summary/…)); var response = await request.close(); // sends the request var result = new StringBuffer(); await for (var contents in response.transform(Utf8Decoder())) { result.write(contents); } List<dynamic> myList = jsonDecode(result.toString()); print(myList[0]['title']); }
– DomDunk
Nov 27 '18 at 12:41
Why does not it work?
– DomDunk
Nov 27 '18 at 12:42
I solved in this way:
– DomDunk
Nov 27 '18 at 18:00
'code' var myList = jsonDecode(result.toString()); List quakes = myList['features']; } 'code'
– DomDunk
Nov 27 '18 at 18:01
import 'dart:io'; import 'dart:convert'; void main() async { var request = await HttpClient().getUrl(Uri.parse('earthquake.usgs.gov/earthquakes/feed/v1.0/summary/…)); var response = await request.close(); // sends the request var result = new StringBuffer(); await for (var contents in response.transform(Utf8Decoder())) { result.write(contents); } List<dynamic> myList = jsonDecode(result.toString()); print(myList[0]['title']); }
– DomDunk
Nov 27 '18 at 12:41
import 'dart:io'; import 'dart:convert'; void main() async { var request = await HttpClient().getUrl(Uri.parse('earthquake.usgs.gov/earthquakes/feed/v1.0/summary/…)); var response = await request.close(); // sends the request var result = new StringBuffer(); await for (var contents in response.transform(Utf8Decoder())) { result.write(contents); } List<dynamic> myList = jsonDecode(result.toString()); print(myList[0]['title']); }
– DomDunk
Nov 27 '18 at 12:41
Why does not it work?
– DomDunk
Nov 27 '18 at 12:42
Why does not it work?
– DomDunk
Nov 27 '18 at 12:42
I solved in this way:
– DomDunk
Nov 27 '18 at 18:00
I solved in this way:
– DomDunk
Nov 27 '18 at 18:00
'code' var myList = jsonDecode(result.toString()); List quakes = myList['features']; } 'code'
– DomDunk
Nov 27 '18 at 18:01
'code' var myList = jsonDecode(result.toString()); List quakes = myList['features']; } 'code'
– DomDunk
Nov 27 '18 at 18:01
add a comment |
Simply the following
List elements = json.decode(response.body);
error: The getter 'body' isn't defined for the class 'HttpClientResponse'. (undefined_getter at [flutter_app] libmain.dart:40)
– DomDunk
Nov 27 '18 at 2:12
add a comment |
Simply the following
List elements = json.decode(response.body);
error: The getter 'body' isn't defined for the class 'HttpClientResponse'. (undefined_getter at [flutter_app] libmain.dart:40)
– DomDunk
Nov 27 '18 at 2:12
add a comment |
Simply the following
List elements = json.decode(response.body);
Simply the following
List elements = json.decode(response.body);
answered Nov 24 '18 at 18:18
Sami KanafaniSami Kanafani
544511
544511
error: The getter 'body' isn't defined for the class 'HttpClientResponse'. (undefined_getter at [flutter_app] libmain.dart:40)
– DomDunk
Nov 27 '18 at 2:12
add a comment |
error: The getter 'body' isn't defined for the class 'HttpClientResponse'. (undefined_getter at [flutter_app] libmain.dart:40)
– DomDunk
Nov 27 '18 at 2:12
error: The getter 'body' isn't defined for the class 'HttpClientResponse'. (undefined_getter at [flutter_app] libmain.dart:40)
– DomDunk
Nov 27 '18 at 2:12
error: The getter 'body' isn't defined for the class 'HttpClientResponse'. (undefined_getter at [flutter_app] libmain.dart:40)
– DomDunk
Nov 27 '18 at 2:12
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53459989%2fhow-can-i-get-a-list-object-by-httpclientresponse%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown