正如您在问题标题中看到的,我需要从URL获取数据类名或id颤振。有一些数据我没有得到它的JSON数据,我需要他们在我的应用程序上显示。我可以使用下面的代码获取数据,但我不能通过类名或id获取任何数据,因为我不知道我需要使用什么。请帮帮我
class _MyHomePageState extends State<MyHomePage> {
String stringResponse;
Future fetcData() async {
http.Response response;
response = await http.get("www.example.com"); //Consider that the URL has just a string such as "This is a string."
if (response.statusCode == 200) {
setState(() {
stringResponse = response.body;
});
} else {
}
}
@override
void initState() {
// TODO: implement initState
fetcData();
super.initState();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Http request"),
),
body: Center(
child: Text(stringResponse.toString()),
),
);
}
}
这里是HTTP包。
这里是一个获得响应的完整方法。
HttpClient client = new HttpClient()
..badCertificateCallback =
((X509Certificate cert, String host, int port) => true);
return client.getUrl(Uri.parse(url)).then((HttpClientRequest request) {
request.headers.set('content-type', 'application/json-patch+json');
request.headers.set('accept', 'application/json');
var response = request.close().timeout(new Duration(seconds: 5));
return response;
}).then((HttpClientResponse response) {
var result = response.transform(utf8.decoder).join();
return result;
}).catchError((onError) {
var result = onError.transform(utf8.decoder).join();
return result;
});
这个错误不是因为你的手机问题,也许这也是一个问题,但按照我的代码;
跟随我的本地。属性文件
sdk.dir=/Users/gloify/Library/Android/sdk
flutter.sdk=/Users/gloify/Downloads/flutter
flutter.buildMode=debug
flutter.versionName=1.0.0
flutter.versionCode=1
flutter.minSdkVersion=27
flutter.targetSdkVersion=33
flutter.compileSdkVersion=33
和在应用级build.gradle中
defaultConfig {
applicationId "com.example.emito"
minSdkVersion localProperties.getProperty('flutter.minSdkVersion').toInteger()
targetSdkVersion localProperties.getProperty('flutter.targetSdkVersion').toInteger()
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}
如果您正在设置localProperties.getProperty('flutter.minSdkVersion').toInteger()作为localProperties.getProperty('flutter.compileSdkVersion').toInteger()
则会发生这种类型的错误。请确保您的默认配置。
就是这样谢谢你