Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/clojure/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Json 如何在flatter中解析此响应,并从API响应中的两个数组的文本字段中获取response的值?_Json_Api_Parsing_Flutter - Fatal编程技术网

Json 如何在flatter中解析此响应,并从API响应中的两个数组的文本字段中获取response的值?

Json 如何在flatter中解析此响应,并从API响应中的两个数组的文本字段中获取response的值?,json,api,parsing,flutter,Json,Api,Parsing,Flutter,我用的是飞镖。我的回答是: {"listroute":[{"id":"1","route_title":"Brooklyn East","no_of_vehicle":null,"fare":"101.00","note":null,"is_active":"no","created_at":"2018-06-02 12:49:21","updated_at":"0000-00-00 00:00:00","vehicles":[{"vec_route_id":"1","id":"1","vehi

我用的是飞镖。我的回答是:

{"listroute":[{"id":"1","route_title":"Brooklyn East","no_of_vehicle":null,"fare":"101.00","note":null,"is_active":"no","created_at":"2018-06-02 12:49:21","updated_at":"0000-00-00 00:00:00","vehicles":[{"vec_route_id":"1","id":"1","vehicle_no":"101","vehicle_model":"101","manufacture_year":"2000","driver_name":"arvind","driver_licence":"544575854","driver_contact":"1305442045","note":"","created_at":"2018-06-02 12:54:13"}]},{"id":"2","route_title":"Brooklyn South","no_of_vehicle":null,"fare":"1010.00","note":null,"is_active":"no","created_at":"2018-06-02 12:50:06","updated_at":"0000-00-00 00:00:00","vehicles":[{"vec_route_id":"3","id":"3","vehicle_no":"2145","vehicle_model":"425","manufacture_year":"2017","driver_name":"amit","driver_licence":"4526320125","driver_contact":"23054420456","note":"","created_at":"2018-06-02 12:57:23"},{"vec_route_id":"2","id":"2","vehicle_no":"1010","vehicle_model":"242","manufacture_year":"2016","driver_name":"abhisekh","driver_licence":"4526320125","driver_contact":"23054420456","note":"","created_at":"2018-06-02 12:56:41"}]},{"id":"3","route_title":"Brooklyn West","no_of_vehicle":null,"fare":"100.00","note":null,"is_active":"no","created_at":"2018-06-02 12:51:00","updated_at":"0000-00-00 00:00:00","vehicles":[]},{"id":"4","route_title":"Uppal","no_of_vehicle":null,"fare":"101.00","note":null,"is_active":"no","created_at":"2018-06-02 12:51:22","updated_at":"0000-00-00 00:00:00","vehicles":[{"vec_route_id":"6","id":"3","vehicle_no":"2145","vehicle_model":"425","manufacture_year":"2017","driver_name":"amit","driver_licence":"4526320125","driver_contact":"23054420456","note":"","created_at":"2018-06-02 12:57:23"},{"vec_route_id":"5","id":"2","vehicle_no":"1010","vehicle_model":"242","manufacture_year":"2016","driver_name":"abhisekh","driver_licence":"4526320125","driver_contact":"23054420456","note":"","created_at":"2018-06-02 12:56:41"},{"vec_route_id":"4","id":"1","vehicle_no":"101","vehicle_model":"101","manufacture_year":"2000","driver_name":"arvind","driver_licence":"544575854","driver_contact":"1305442045","note":"","created_at":"2018-06-02 12:54:13"}]},{"id":"5","route_title":"MAHE","no_of_vehicle":null,"fare":"101.00","note":null,"is_active":"no","created_at":"2018-06-02 12:51:37","updated_at":"0000-00-00 00:00:00","vehicles":[{"vec_route_id":"7","id":"2","vehicle_no":"1010","vehicle_model":"242","manufacture_year":"2016","driver_name":"abhisekh","driver_licence":"4526320125","driver_contact":"23054420456","note":"","created_at":"2018-06-02 12:56:41"}]},{"id":"6","route_title":"CMD Chowk","no_of_vehicle":null,"fare":"200.00","note":null,"is_active":"no","created_at":"2018-06-02 12:51:58","updated_at":"0000-00-00 00:00:00","vehicles":[]},{"id":"9","route_title":"x","no_of_vehicle":null,"fare":"10.00","note":null,"is_active":"no","created_at":"2018-06-11 07:22:46","updated_at":"0000-00-00 00:00:00","vehicles":[]},{"id":"10","route_title":"xy","no_of_vehicle":null,"fare":"10.00","note":null,"is_active":"no","created_at":"2018-06-11 07:22:53","updated_at":"0000-00-00 00:00:00","vehicles":[]},{"id":"11","route_title":"mmm","no_of_vehicle":null,"fare":"10.00","note":null,"is_active":"no","created_at":"2018-06-11 11:48:02","updated_at":"0000-00-00 00:00:00","vehicles":[]}],"childs":[{"transport_fees":"0.00","vehroute_id":"6","student_session_id":"1","fees_discount":"0.00","class_id":"1","class":"Nursery A","section_id":"1","section":"A","id":"1","admission_no":"1","roll_no":"01052018","admission_date":"2018-05-30","firstname":"Amit","lastname":"Teja","image":"uploads\/student_images\/no_image.png","mobileno":"09021902190","email":"amit@mailinator.com","state":null,"city":null,"pincode":null,"religion":"Teja","cast":"Gen","dob":"2016-07-06","current_address":"ttetet\r\nasdasdasd","previous_school":"","guardian_is":"father","permanent_address":"ttetet\r\nasdasdasd","category_id":"1","adhar_no":"iewk123kaqws12","samagra_id":"iewk123kaqws12","bank_account_no":"9999999999999999999999","bank_name":"CITY Bank","ifsc_code":"city000010","guardian_name":"Sumit","guardian_relation":"Father","guardian_phone":"8309632153","guardian_address":"ttetet\r\nasdasdasd","is_active":"no","created_at":"2018-06-06 11:52:43","updated_at":"0000-00-00 00:00:00","father_name":"Sumit","father_phone":"Teja","father_occupation":"Business","mother_name":"Sumitra","mother_phone":"9876543211","mother_occupation":"House Wife","guardian_occupation":"Business","gender":"Male","rte":"Yes","guardian_email":"sumit@mailinato.com"},{"transport_fees":"0.00","vehroute_id":"0","student_session_id":"2","fees_discount":"0.00","class_id":"1","class":"Nursery A","section_id":"1","section":"A","id":"2","admission_no":"2","roll_no":"01052019","admission_date":"2018-06-01","firstname":"vibhav","lastname":"Teja","image":"uploads\/student_images\/no_image.png","mobileno":"7894561230","email":"vibhav@gmail.com","state":null,"city":null,"pincode":null,"religion":"Teja","cast":"Gen","dob":"2018-06-09","current_address":"ttetet\r\nasdasdasd","previous_school":"","guardian_is":"father","permanent_address":"ttetet\r\nasdasdasd","category_id":"1","adhar_no":"iewk123kaqws12","samagra_id":"iewk123kaqws12","bank_account_no":"125423625642","bank_name":"City Bank","ifsc_code":"12542362","guardian_name":"Sumit","guardian_relation":"Father","guardian_phone":"8309632153","guardian_address":"ttetet\r\nasdasdasd","is_active":"no","created_at":"2018-06-06 11:29:26","updated_at":"0000-00-00 00:00:00","father_name":"Sumit","father_phone":"Teja","father_occupation":"Business","mother_name":"Sumitra","mother_phone":"9876543211","mother_occupation":"House Wife","guardian_occupation":"Business","gender":"Male","rte":"Yes","guardian_email":"sumit@mailinato.com"},{"transport_fees":"0.00","vehroute_id":"6","student_session_id":"11","fees_discount":"0.00","class_id":"2","class":"Nursery B","section_id":"2","section":"B","id":"5","admission_no":"1234-A1","roll_no":"0105202010","admission_date":"2018-06-11","firstname":"Rajat","lastname":"Teja","image":"uploads\/student_images\/no_image.png","mobileno":"07697019875","email":"rajat@gmail.com","state":null,"city":null,"pincode":null,"religion":"Teja","cast":"","dob":"2018-06-14","current_address":"ttetet\r\nasdasdasd","previous_school":"","guardian_is":"father","permanent_address":"ttetet\r\nasdasdasd","category_id":"3","adhar_no":"","samagra_id":"","bank_account_no":"","bank_name":"","ifsc_code":"","guardian_name":"Sumit","guardian_relation":"Father","guardian_phone":"8309632153","guardian_address":"ttetet\r\nasdasdasd","is_active":"no","created_at":"2018-06-11 07:35:54","updated_at":"0000-00-00 00:00:00","father_name":"Sumit","father_phone":"Teja","father_occupation":"Business","mother_name":"Sumitra","mother_phone":"9876543211","mother_occupation":"House Wife","guardian_occupation":"Business","gender":"Female","rte":"No","guardian_email":""}]}

如何解析这种类型的输出?

如果是字符串,可以使用
jsonDecode
json.decode

import 'dart:convert' show jsonDecode, json;

Map<String,dynamic> parseResponse(String response) {
  return jsonDecode(response);
}
import'dart:convert'显示jsonDecode,json;
映射解析响应(字符串响应){
返回jsonDecode(响应);
}

问题中的数据似乎已被解析。您可能想知道如何使用接收到的数据。这里有一个例子

class HomeState extends State<Home> {
List listRoute = [];

Future getData() async {
    http.Response res = await http.get(
        'http://app.webcraft.co.in/eschool/parent/routejson?parent_id=2&student_id=1');
    Map mapRes = json.decode(res.body);
    print('Response from server: $mapRes');
    setState(() {
    listRoute = mapRes['listroute'];
    });
}

@override
void initState() {
    super.initState();
    getData();
}

@override
Widget build(BuildContext context) {
    return new Scaffold(
    appBar: new AppBar(
        title: new Text('HTTP demo'),
    ),
    body: listRoute.length == 0
        ? new Container()
        : new ListView(
            children: listRoute
                .map((route) => new ListTile(
                    title: new Text(route['route_title']),
                    subtitle: new Text(route['fare'])))
                .toList(),
            ),
    );
}
}
class HomeState扩展状态{
列表listRoute=[];
Future getData()异步{
Response res=wait http.get(
'http://app.webcraft.co.in/eschool/parent/routejson?parent_id=2&student_id=1');
Map mapRes=json.decode(res.body);
打印('responsefromserver:$mapRes');
设置状态(){
listRoute=mapRes['listRoute'];
});
}
@凌驾
void initState(){
super.initState();
getData();
}
@凌驾
小部件构建(构建上下文){
归还新脚手架(
appBar:新的appBar(
标题:新文本(“HTTP演示”),
),
正文:listRoute.length==0
?新容器()
:新建列表视图(
儿童:listRoute
.map((路线)=>新建列表块(
标题:新文本(路线['route_title']),
字幕:新文本(路线[‘票价]))
.toList(),
),
);
}
}
或者您可能需要了解,您收到的是一个
Map
,其中key
listroute
的值是您需要迭代的列表

如果您无法访问地图中的其他密钥或数据,请在评论中询问


注意:如果您无法理解/读取数据,有几个站点可以查看json数据,格式非常好,如

您尝试了什么?欢迎使用Stackoverflow。当提出问题时,如果您提供代码,您将得到更好的答案。添加到目前为止您已经尝试过的内容。另外,请检查您是否应该向我们提供示例或至少您尝试过的内容,以便我们能够提供帮助。不管你有没有尝试过这个:?嘿,谢谢,我需要解析listroute和vihicles数组值的值,并在文本中使用它。我需要在文本中显示车辆值以及其他listroutesvalues@AyushJainWebCraftIT获取此错误-未处理的异常:NoSuchMethodError:对null调用了方法“[]”。E/flatter(24765):接收者:null E/flatter(24765):在我的情况下,尝试调用:[(“银行名”)在textview中获取的非列表响应,但每次都出现此错误