Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

api - Fetch complex data from the internet

am working on a machine app which fetches data from the server by using HTTP request. the problem is that the api is providing more than 50000 obejects nested. when i make the api request it takes more than 2 minutes. is there any solution so that i can fetch the data faster ?

P.s. I can't use pagination because am not gonna to build Listview with it. The fetched data are just there to be selected as property not more. So when user needs to configure machine, he will get more than 20 properties 3 of them are Lists that present the fetched data simple as Search list.

my data is somthing like this : every object has actually a list that contains at least 50 objects.

{
    "mainCategories": [
        {
            "mainCategoryName": "Agriculture",
            "labelDE": "Landtechnik",
            "labelEN": "Agriculture",
            "categories": [
                {
                    "categoryCode": "Tractor",
                    "categoryName": "Tractor",
                    "labelDE": "Traktor",
                    "labelEN": "Tractor",
                    "subCategories": [
                        {
                            "subcategoryCode": "Tractor",
                            "subcategoryName": "Tractor",
                            "labelDE": "Traktor",
                            "labelEN": "Tractor",
                            "subcategoryOptions": [
                                {
                                    "optionCode": "brand",
                                    "optionName": "brand",
                                    "LabelDE": "Hersteller",
                                    "LabelEN": "Make",
                                    "dataType": "Text"
                                },
                                {
                                    "optionCode": "model",
                                    "optionName": "model",
                                    "LabelDE": "Modell",
                                    "LabelEN": "Model",
                                    "dataType": "Text"
                                },
                                {
                                    "optionCode": "yearOfConstruction",
                                    "optionName": "yearOfConstruction",
                                    "LabelDE": "Baujahr",
                                    "LabelEN": "Year of Construction",
                                    "dataType": "int"
                                },
                                {
                                    "optionCode": "powerHP",
                                    "optionName": "powerHP",
                                    "LabelDE": "Leistung in PS",
                                    "LabelEN": "Horse Power",
                                    "dataType": "int"
                                },
                                {
                                    "optionCode": "additionalControlUnit",
                                    "optionName": "additionalControlUnit",
                                    "LabelDE": "Zus?tzliche Steuerger?te",
                                    "LabelEN": "Additional Control Unit",
                                    "dataType": "enum",
                                    "enums": [
                                        {
                                            "enumCode": "mechanic",
                                            "enumName": "mechanic",
                                            "LabelDE": "mechanisch",
                                            "LabelEN": "mechanic"
                                        },
                                        {
                                            "enumCode": "electric",
                                            "enumName": "electric",
                                            "LabelDE": "elektrisch",
                                            "LabelEN": "electric"
                                        }
                                    ]
                                },
                                {
                                    "optionCode": "hasCabin",
                                    "optionName": "hasCabin",
                                    "LabelDE": "Kabine vorhanden",
                                    "LabelEN": "Cabin",
                                    "dataType": "boolean"
                                },
                                {
                                    "optionCode": "airCondition",
                                    "optionName": "airCondition",
                                    "LabelDE": "Klimaanlage",
                                    "LabelEN": "Air Condition",
                                    "dataType": "boolean"
                                }
                            ]
                        }
                    ]
                }
            ]
        }
    ]
} 

i using the following code :

static Future<http.Response> fetchDataFromApi(http.Client client) async {
    final response = await client.get(apiURL);

    if (response.statusCode == 200) {
      final jsonResponse = jsonDecode(response.body);
      modelMachineApi = new ModelMachineApi.fromJson(jsonResponse);
      print("The Api call has successed");
      print(modelMachineApi.categories[0].labelDE);
    }

   
    return response;
  }
question from:https://stackoverflow.com/questions/65830490/fetch-complex-data-from-the-internet

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share

2.1m questions

2.1m answers

63 comments

56.6k users

...