2017-10-06 118 views
0

我使用GET JSON請求知道事務的狀態(檢查每5秒):如何將這些字符串轉換爲布爾值?

string webAddr = "https://shapeshift.io/txStat/" + textBox1.Text; 

     var httpWebRequest = (HttpWebRequest)WebRequest.Create(webAddr); 
     httpWebRequest.ContentType = "application/json; charset=utf-8"; 
     httpWebRequest.Method = "GET"; 

     var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse(); 
     using (var streamReader = new StreamReader(httpResponse.GetResponseStream())) 
     { 
      var responseText = streamReader.ReadToEnd(); 
      var apiResponse = JsonConvert.DeserializeObject<TransactionStatus>(responseText); 
     } 

     if (TransactionStatus.status = "no_deposits") 
     { 
      label7.Text = "Pending.."; 
     } 
     else if (TransactionStatus.status = "received") 
     { 
      label7.Text = "Received.."; 
     } 
     else if (TransactionStatus.status = "complete") 
     { 
      label7.Text = "Completed !"; 
     } 
     else 
     { 
      label7.Text = "..."; 
     } 

我的問題是,我無法檢查該字符串值,因爲它需要「布爾」。我怎樣才能改變這個布爾?或者有任何其他方法可以做我想要做的檢查?謝謝 !

+2

你正在通過使用一個等號在你的'if'語句中賦值。更改'TransactionStatus.status = ...'到'TransactionStatus.status == ...' – mrogers

+0

哈哈我很轉儲,謝謝! – EduardLula

+0

我建議使用switch(TransactionStatus.status)而不是這個if if else if噩夢。 – Filburt

回答

2

== not =。

TransactionStatus.status = "no_deposits" 

應該

TransactionStatus.status == "no_deposits" 

否則就認爲你分配一個值狀態,沒有比較的。

+0

是的,發佈後得到它。無論如何,謝謝 – EduardLula

+0

我發佈後多次解決問題很有趣。 – GrandMasterFlush

相關問題