如何获得无限递归?

问题描述 投票:-1回答:2

我有来自客户端的OAuth2.0 Json数据。而且我必须将所有数据从特定的API提取到我的SQL数据库中。此API进行了一些验证,例如一次只能显示250个数据,接下来我们再次使用不同的参数运行API。这样的API数据结构。

{
  "next": URL or null,                  // URL of the next page (same as the requested URL, but with the page query parameter incremented)
  "previous": URL or null,              // URL of the previous page
  "results": array of result objects    // the results follow the same format as `:endpoint/:id`
}

对于下一个或上一个数据,我们必须运行URL所在的上一个或下一个。

i使从该API导入数据到我的SQL数据的自动化。但是经过一些循环后,我得到了这个错误。enter image description here

并且在其余数据之后,我无法导入我的SQL数据库。我正在使用Dr.chrono API将其数据导入到我的系统中。我不知道该怎么办。

代码下方:-

private void recursivemethod(List<string> lstarray, String token, string URL, string flag, StringBuilder sb)
        {


                RestClient client = new RestClient(URL);

                RestRequest request = new RestRequest(Method.GET);
                request.Parameters.Clear();
                client.Timeout = -1;
                request.AddHeader("authorization", "Bearer " + token);
                request.AddHeader("Content-Type", "application/x-www-form-urlencoded");
                request.AddHeader("cache-control", "no-cache");
                IRestResponse response = client.Execute(request);
                ////Using dynamic keyword with JsonConvert.DeserializeObject, here you need to import Newtonsoft.Json  


                dynamic myObject = JsonConvert.DeserializeObject(response.Content);
                if (flag == "patient")
                {
                    PatientMain items = JsonConvert.DeserializeObject<PatientMain>(response.Content);
                    int i = 0;
                    lstarray.Clear();
                    foreach (var type in items.results)
                    {
                        i++;

                        lstarray.Add("INSERT INTO drchrono_patient(id,chart_id,first_name,middle_name,last_name,date_of_birth,gender,social_security_number,race,ethnicity,preferred_language,patient_status,home_phone,cell_phone,office_phone,email,address,city,state,zip_code,doctor,primary_care_physician,date_of_first_appointment,date_of_last_appointment,default_pharmacy,referring_source,copay,updated_at) VALUES ('" + convertQuotes(type.id) + "','" + convertQuotes(type.chart_id) + "','" + convertQuotes(type.first_name) + "','" + convertQuotes(type.middle_name) + "','" + convertQuotes(type.last_name) + "','" + convertQuotes(type.date_of_birth) + "','" + convertQuotes(type.gender) + "','" + convertQuotes(type.social_security_number) + "','" + convertQuotes(type.race) + "','" + convertQuotes(type.ethnicity) + "','" + convertQuotes(type.preferred_language) + "' ,'" + convertQuotes(type.patient_status) + "','" + convertQuotes(type.home_phone) + "','" + convertQuotes(type.cell_phone) + "','" + convertQuotes(type.office_phone) + "','" + convertQuotes(type.email) + "','" + convertQuotes(type.address) + "','" + convertQuotes(type.city) + "','" + convertQuotes(type.state) + "','" + convertQuotes(type.zip_code) + "','" + convertQuotes(type.doctor) + "','" + convertQuotes(type.primary_care_physician) + "','" + convertQuotes(type.date_of_first_appointment) + "','" + convertQuotes(type.date_of_last_appointment) + "','" + convertQuotes(type.default_pharmacy) + "','" + convertQuotes(type.referring_source) + "','" + convertQuotes(type.copay) + "','" + convertQuotes(type.updated_at) + "') ");


                    }
                    string result = dbf.pExecuteQueryList(lstarray);
                    if (items.next != null)
                    {
                        URL = items.next;
                        recursivemethod(lstarray, token, URL, flag, sb);
                    }
                }
}
c# asp.net api asp.net-web-api chrono
2个回答
0
投票

您有一个StackOverflow exception。从Microsoft文档中:


0
投票

考虑使用循环而不是递归。您可以使大部分逻辑保持相同,并重新构建重复方式。让我们首先更改方法签名以返回一个值。这样的事情应该起作用:

© www.soinside.com 2019 - 2024. All rights reserved.