【发布时间】:2014-08-23 09:39:05
【问题描述】:
我想制作一个程序,从 API 生成的 JSON 文件中读取一些数据。
这是该 JSON 文件的示例:
{"block4o": {
"id": 20153910,
"name": "Block4o",
"profileIconId": 616,
"revisionDate": 1408783284000,
"summonerLevel": 30
}}
我需要做的是从中获取例如 id 和名称。 到目前为止,这是我的代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web;
using System.IO;
using System.Net;
namespace ConsoleApplication30
{
class Program
{
static void Main(string[] args)
{
}
public void HowToMakeRequestsToHttpBasedServices()
{
Uri serviceUri = new Uri("https://eune.api.pvp.net/api/lol/eune/v1.4/summoner/by-name/Block4o?api_key=****");
WebClient downloader = new WebClient();
downloader.OpenReadCompleted += new OpenReadCompletedEventHandler(downloader_OpenReadCompleted);
downloader.OpenReadAsync(serviceUri);
}
void downloader_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
{
if (e.Error == null)
{
Stream responseStream = e.Result;
// Continue working with responseStream here...
}
}
}
}
任何想法都将不胜感激:)
【问题讨论】: