2016-10-29 45 views
0

我想要使用SurveyMonkey API來獲取問題&在.NET應用程序中的答案,並且我正在起訴.Net包裝。 我可以獲得有關調查的一般信息,例如(surveyId,問題數量等),但是當我嘗試獲取收集器或問題或響應或任何其他對象時,出現錯誤,指出這些對象爲空。 這裏是一塊的什麼,我試圖做System.NullReferenceException與SurveyMonkey .Net包裝

string apiKey = "key"; 
string token ="token"; 
var sm = new SurveyMonkeyApi(apiKey, token); 
List<Survey> surveys = sm.GetSurveyList(); 

foreach(Survey s in surveys) 
{ 
      //this link bellow is working fine 
      MessageBox.Show("Survey Id:"+s.SurveyId); 

      List<Collector> collectorList = s.Collectors; 
      //this line bellow give a System.NullReferenceException in "collectorList" 
      foreach (Collector c in collectorList) 
      { 
      //Other instructions 

      } 
} 

PS代碼:我試圖在PHP包裝版本,它是工作的罰款。

+0

我假設s.Collectors提取該調查的收集器,但它做了什麼確切的API調用?它回來了什麼?它甚至打電話,或者你必須首先填充收藏家,然後你可以調用's.Collectors'?我需要看到.NET包裝程序代碼來幫助調試,現在它看起來像s.Collectors是空的。 –

+0

是s.Collectors肯定爲null。我認爲包裝的代碼源可在[鏈接](https://github.com/bcemmett/SurveyMonkeyApi) – GENE

+0

可能重複[什麼是NullReferenceException,我該如何解決它?](http:// stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-and-how-do-i-fix-it) – Enigmativity

回答

2

包裝器的GetSurveyList方法調用/調查端點(https://developer.surveymonkey.net/api/v3/#surveys)。像Pages,Questions和Collectors這樣的集合將不會被填充。如果你想獲得相關的收藏家,你需要進行另一次API調用。這將爲你做:

foreach (Survey s in surveys) 
     { 
      List<Collector> collectorList = sm.GetCollectorList(s.Id); 
      foreach (Collector c in collectorList) 
      { 
       //Other instructions 
      } 
     } 
+0

謝謝you.it工作:) – GENE