C#でWebAPIからjsonを繰り返し取得したいのですが、1回目の取得はうまくいきますがループで回すと同じ値しか取得できません。
ボタンを押すことで取得の開始を考えていますが、ボタンは不要でも良いとは考えています。
C#は使い始めたばかりで、UWPについてもほとんど知識がない状況です。
根本が間違っているかもしれませんが、よろしくお願いいたします。
C#
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
using Windows.Web.Http;
using Newtonsoft.Json.Linq;
using Windows.Devices.Gpio;
using System.Threading.Tasks;
// 空白ページのアイテム テンプレートについては、http://go.microsoft.com/fwlink/?LinkId=402352&clcid=0x409 を参照してください
namespace MaterialMatching_WebAPI
{
/// <summary>
/// それ自体で使用できる空白ページまたはフレーム内に移動できる空白ページ。
/// </summary>
public sealed partial class MainPage : Page
{
private GpioPin pin;
public MainPage()
{
this.InitializeComponent();
}
private async void Button_Click(object sender, RoutedEventArgs e) { //ここにボタンがクリックされた時の処理を書く for (; ; ) { string conKbn = "0"; string machine_cd = "XXXX-01"; string endpoint = string.Format( "http://xxx.xxx.xxx.xxx/WakoWebApi/DBService/getMachine_mst?conKbn={0}&machine_cd={1}", conKbn, machine_cd ); HttpClient client = new HttpClient(); HttpResponseMessage result = await client.GetAsync(new Uri(endpoint)); string json = await result.Content.ReadAsStringAsync(); //jsonを解析して結果を取得する string kekka = json; if (kekka == "0") { textBlock1.Text = ”OK"; } else { textBlock1.Text = "NG"; } } } }
}

回答4件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/12/14 14:15
2017/12/14 14:22
2017/12/14 14:27
2017/12/14 14:32
2017/12/14 14:37
2017/12/14 14:39
2017/12/14 14:44
2017/12/14 14:47
2017/12/14 14:47
2017/12/14 14:58
2017/12/14 15:02
2017/12/14 15:04
2017/12/14 15:12
2017/12/14 15:20
2017/12/14 15:22
2017/12/14 23:23