C#
2017.12.17 23:44
HTTP로 JSON을 받아와서 ListView에 표시하는 샘플
조회 수 102259 추천 수 0 댓글 0
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Newtonsoft.Json.Linq;
using System.Net;
using System.IO;
namespace ListViewSample
{
/// <summary>
/// MainWindow.xaml에 대한 상호 작용 논리
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void Refresh_Button_Click(object sender, RoutedEventArgs e)
{
string json = this.Request_Json();
this.ParseJson(json);
}
private string Request_Json()
{
string result = null;
Console.WriteLine("url : " + url);
try
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream stream = response.GetResponseStream();
StreamReader reader = new StreamReader(stream);
result = reader.ReadToEnd();
stream.Close();
response.Close();
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
return result;
}
private void ParseJson(String json)
{
List<Issue> issues = new List<Issue>();
JObject obj = JObject.Parse(json);
JArray array = JArray.Parse(obj["issues"].ToString());
foreach (JObject itemObj in array)
{
Issue issue = new Issue();
issue.Subject = itemObj["subject"].ToString();
issue.Done = itemObj["done_ratio"].ToString();
issue.Author = itemObj["author"]["name"].ToString();
issues.Add(issue);
}
IssueListView.ItemsSource = issues;
}
private void Clear_Button_Click(object sender, RoutedEventArgs e)
{
IssueListView.ItemsSource = null;
}
}
}
URL: http://susemi99.kr/1651
번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|---|
185 | Information | MySQL 테이블의 엔진정보 출력 | LionHeart | 2018.06.15 | 39424 |
184 | C# | 유용한 사이트 | LionHeart | 2018.06.15 | 47805 |
183 | Information | MySQL WHERE절의 서브쿼리(Sub Query) sample | LionHeart | 2018.06.06 | 69902 |
182 | Information | 보험회사의 '알릴 의무사항' 질문지. | LionHeart | 2018.05.22 | 40254 |
181 | OS | CentOS 7 웹서버 구축 [APM] - YUM설치 (최신버전) | LionHeart | 2018.05.11 | 42579 |
180 | OS | 윈도우에서 VPN 설정 | LionHeart | 2018.04.24 | 47795 |
179 | C# | C# example site | LionHeart | 2018.04.07 | 53465 |
178 | OS | Free Video Converter | LionHeart | 2018.04.07 | 52129 |
177 | C# | 멀티코어 프로그램 | LionHeart | 2018.03.23 | 48250 |
176 | Information | 텔레그램 봇(botfather) | LionHeart | 2018.03.16 | 205551 |
175 | Computer | MySQL 바이너리 로그 삭제 | LionHeart | 2018.03.15 | 39613 |
174 | OS | 원키 고스트 | LionHeart | 2018.03.14 | 45693 |
173 | C# | [스크랩] c# 크로스 스레드(CheckForIllegalCrossThreadCalls) | LionHeart | 2018.02.28 | 44985 |
172 | Information | 국가별 거래시간 | LionHeart | 2018.02.25 | 42458 |
171 | Information | 넷기어 R7000의 멀린펌 적용 및 원상복구 | LionHeart | 2018.02.18 | 76959 |
170 | Information | System Trading 정리글 | LionHeart | 2018.02.12 | 43152 |
169 | Information | [스크랩] 법인사업자가 사업자가 아닌 개인으로부터 매입 시 회계 및 세무처리 | LionHeart | 2018.02.12 | 60652 |
168 | Information | Top 8 RESTful API Frameworks for PHP | LionHeart | 2018.02.08 | 40410 |
167 | Information | MySQL Charset 관련정보 | LionHeart | 2018.02.08 | 40904 |
166 | Information | Simple PHP MySQL Rest API Sample Example Tutorial | LionHeart | 2018.02.08 | 66860 |