1

I try to run below code in flutter App but it loads half JSON data, same API when running for a web app it works fine. Any idea how to solve this issue?

Example

   Future <List> test() async{
   
   final response = await http.post(
       "https://xyz/allData",

    body: jsonEncode({
      "email": "email"
    
    }),
    headers: {
      HttpHeaders.contentTypeHeader: ContentType.json.toString(),
      HttpHeaders.authorizationHeader: token
    });

     final data= json.decode(response.body);
      OR
     Map<String, dynamic> data =json.decode(response.body);
      

Error

half JSON fetch by above code below content I recieved :

  {success: true, msg: Loaded, content: 
  {total: 3, on: 0, off: 3, 
    on: {}, 
    off: {
    11: {id: 11, last_data: N/A,value: {N/A: {name: N/A, value: N/A}},
    name: 01, type: temp, upper: 20, lower: 10, email: [], phn_list: [], id: 01,status: 0, freq: 10, description: 01, status_notf: 0, lat_map: 0, lng_map: 0, html: html}, 

   12: {id: 12, last_data: N/A, value: {N/A: {name: N/A, value: N/A}},
name: 02, type: temp, upper: 20, lower: 10, email: [], phn_list: [], id: 02, status: 0,freq: 10, description: 02, status_notf: 0, lat_map: 0, lng_map 
  • what do you mean by half json fetch by above code? the json fetched is not complete? what you get from your response.body? – xion Jun 22 '20 at 07:45
  • When I run the above code I received nearly 30% of actual JSON data. Actual JSON content is around 300 {key, value}pairs and I received nearly 100{key, value}. – user13789881 Jun 22 '20 at 08:24
  • 1
    are you doing print(yourData)? that will truncate displaying data. if you go through the actually data, it's actually 300 instead of 100. – xion Jun 22 '20 at 08:56
  • Hi ! what kind of error do you get when doing `json.decode` ? and is your response statusCode correct ? – Hadrien Lejard Jun 22 '20 at 08:58
  • please check, I updated error section – user13789881 Jun 22 '20 at 09:20
  • @xion Yes, I used print (data), but for other APIs, the print function works perfectly,and if print function truncate, then how to know the full actual data is receiving or not? – user13789881 Jun 22 '20 at 10:46
  • AFAIK, it will always be full actual data, unless your api return otherwise. Cause print will be very heavy if you're receiving thousands of object or more. – xion Jun 22 '20 at 12:09
  • Thanks @xion due to print function I received half JSON – user13789881 Jun 24 '20 at 11:22

0 Answers0