我没有在我的应用程序上获得输出,它应该提供类似许多问题的输出,即如何在我的Flutter应用程序中播放json数据
class AppState extends State<AppName>{
var name ;
var email ;
int cgpa ;
TextEditingController user = new TextEditingController();
String url = 'http://10.42.0.243:8000/students/';
getData(String username) async{
String profile = url+'?search='+username;
var res = await http.get(profile,headers: {"Accept":"application/json"});
print(res.body);
debugPrint(res.body);
var resBody = json.decode(res.body);
name = resBody['sname'].toString();
email = resBody['email'].toString();
cgpa = resBody['cgpa'] ;
debugPrint(name);
setState(() {
print("Success");
});
}
错误输出: 正在执行热装... 正在将文件同步到设备Moto G 5 Plus ... 在389毫秒内重新加载576个库中的0个。 E / BpSurfaceComposerClient(28411):交易失败(-1) E / BpSurfaceComposerClient(28411):交易失败(-1) I / flutter(28411):[{“ id”:1,“ sname”:“ Ashutosh Lokhande”,“ email”:“ 2016bit053@sggs.ac.in”,“ year”:“ 2016”,“ cgpa”: 7.2}] I / flutter(28411):[{“ id”:1,“ sname”:“ Ashutosh Lokhande”,“ email”:“ 2016bit053@sggs.ac.in”,“ year”:“ 2016”,“ cgpa”: 7.2}] E / flutter(28411):[错误:flutter / lib / ui / ui_dart_state.cc(148)]未处理的异常:类型'String'不是'index'的'int'类型的子类型 E / flutter(28411):#0 AppState.getData(package:json_flutter / main.dart:28:19) E /颤振(28411): E / flutter(28411):#1 AppState.build。 (包裹:json_flutter / main.dart:56:34) E / flutter(28411):#2 _InkResponseState._handleTap(包:flutter / src / material / ink_well.dart:654:14) E / flutter(28411):#3 _InkResponseState.build。 (包:flutter / src / material / ink_well.dart:729:32) E / flutter(28411):#4 GestureRecognizer.invokeCallback(包:flutter / src / gestures / recognizer.dart:182:24) E / flutter(28411):#5 TapGestureRecognizer._checkUp(包:flutter / src / gestures / tap.dart:365:11) E / flutter(28411):#6 TapGestureRecognizer.handlePrimaryPointer(包:flutter / src / gestures / tap.dart:275:7) E / flutter(28411):#7 PrimaryPointerGestureRecognizer.handleEvent(package:flutter / src / gestures / recognizer.dart:455:9) E / flutter(28411):#8 PointerRouter._dispatch(软件包:flutter / src / gestures / pointer_router.dart:75:13) E / flutter(28411):#9 PointerRouter.route(包:flutter / src / gestures / pointer_router.dart:102:11) E / flutter(28411):#10 GestureBinding.handleEvent(package:flutter / src / gestures / binding.dart:218:19) E / flutter(28411):#11 GestureBinding.dispatchEvent(软件包:flutter / src / gestures / binding.dart:198:22) E / flutter(28411):#12 GestureBinding._handlePointerEvent(软件包:flutter / src / gestures / binding.dart:156:7) E / flutter(28411):#13 GestureBinding._flushPointerEventQueue(package:flutter / src / gestures / binding.dart:102:7) E / flutter(28411):#14 GestureBinding._handlePointerDataPacket(包:flutter / src / gestures / binding.dart:86:7) E / flutter(28411):#15 _rootRunUnary(dart:async / zone.dart:1136:13) E / flutter(28411):#16 _CustomZone.runUnary(dart:async / zone.dart:1029:19) E / flutter(28411):#17 _CustomZone.runUnaryGuarded(dart:async / zone.dart:931:7) E / flutter(28411):#18 _invoke1(dart:ui / hooks.dart:263:10) E / flutter(28411):#19 _dispatchPointerDataPacket(dart:ui / hooks.dart:172:5) E / flutter(28411):