###前提・実現したいこと
現在c#を学習している初心者です。
今回作成しているプログラムは、zaifというbitcoinの取引所のapi(https://corp.zaif.jp/api-docs/)を使用して、bitcoinの終値を定期的に更新し、表示をするアプリケーションです。今回は、プログラムの勉強と、jsonというフォーマットの勉強もかねて、外部のライブラリ(json.netとかDynamic json)などは使わず、自分でjsonをシリアライズすることにしました。
###発生している問題・エラーメッセージ
テストすると、ビルドはできるのですが、ハンドルされていない例外が発生します。
###該当のソースコード
※コメントは自分が分かる程度にしか書いていません。
もっと無駄のないソースコードの書き方などありましたらアドバイスいただけると幸いです。
C#
1using System; 2using System.Collections.Generic; 3using System.ComponentModel; 4using System.Data; 5using System.Drawing; 6using System.Linq; 7using System.Text; 8using System.Windows.Forms; 9using System.Net; 10 11 12 13 14 15namespace WindowsFormsApplication14 16{ 17 18 public partial class Form1 : Form 19 { 20 21 public Form1() 22 { 23 InitializeComponent(); 24 } 25 public static int CountChar(string s, char c) 26 { 27 return s.Length - s.Replace(c.ToString(), "").Length; 28 } 29 public void jsondecode(string input) 30 31 { 32 33 34 } 35 36 private void Form1_Load(object sender, EventArgs e) 37 { 38 timer1.Start(); 39 } 40 41 private void timer1_Tick(object sender, EventArgs e) 42 { 43 44 using (WebClient webClient = new WebClient()) 45 { 46 47 string str = webClient.DownloadString("https://api.zaif.jp/api/1/last_price/btc_jpy"); 48 Boolean y = false;//キーかどうか 49 Boolean y2 = false;//値かどうか 50 int len = str.Length;//取得した文字数取得 51 int cc = CountChar(str,',');//,の数をカウント 52 string[,] str2 = new string[cc,2]; 53 string[] stra = new string[len];//文字列を分割して入れるための配列宣言 54 int y3 = 0;//何個目のオブジェクトか記録用 55 for (int i = 0; i < len; i++ ) {//文字数回繰り返すfor 56 stra[i] = str.Substring(i,1);//i文字目の文字をstra[i]に代入 57 } 58 for (int i = 0; i < len; i++) 59 { 60 61 switch ( stra[i] ) 62 { 63 case "\"": 64 if(y == false) 65 { 66 y = true; 67 68 } 69 else 70 { 71 y = false; 72 73 } 74 break; 75 case ":": 76 y2 = true; 77 break; 78 case "{":break; 79 case "}":break; 80 case "^":break; 81 case ",": 82 if (y2 == true) 83 { 84 y2 = false; 85 } 86 y3++; 87 break; 88 case "[":break; 89 case "]":break; 90 default: 91 if (y == true || y2 == true) 92 { 93 if (y == true) { 94 str2[y3 - 1, 0] = str2[y3 - 1, 0] + stra[i]; 95 } 96 if (y2 == true) 97 { 98 str2[y3 - 1, 1] = str2[y3 - 1, 1] + stra[i]; 99 100 } 101 } 102 break; 103 104 105 106 } 107 108 109 } 110 111 112 113 label1.Text = str2[0, 0] + str2[0, 1] + "円"; 114 115 } 116 } 117 118 private void button1_Click(object sender, EventArgs e) 119 { 120 121 122 } 123 124 } 125 126 }
###試したこと
googleで検索し、ほかの方の事例を見ましたが、当方の検索能力の低さと、知識不足が故に原因特定には至りませんでした。
###補足情報
visual studio 2015 communityを使用しています。

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/10/29 14:53