作者的话
我承认,我一开始把这玩意儿想的超级复杂
本质其实就是,访问他的url,获取源代码,源代码为json值,通过后端转化为json对象,在进行json对象的编辑
对了
记得要新引用using Newtonsoft.Json;
效果截图
源代码
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Web;
using System.Web.Helpers;
namespace APIshow
{
public class ApiHelper
{
public ApiHelper()
{
GetJson();
}
JObject jo;
public void GetJson()
{
string api = "https://interface.sina.cn/news/wap/fymap2020_data.d.json";
WebRequest req = WebRequest.Create(api);
WebResponse res = req.GetResponse();
Stream resStream = res.GetResponseStream();
StreamReader sr = new StreamReader(resStream, Encoding.UTF8);
string contentHtml = sr.ReadToEnd();
string jsonText = contentHtml;
jo = (JObject)JsonConvert.DeserializeObject(jsonText);//或者JObject jo = JObject.Parse(jsonText);
}
public string GetAll()
{
return jo["data"]["gntotal"].ToString();
}
public string GetDeal()
{
return jo["data"]["deathtotal"].ToString();
}
public string GetCure()
{
return jo["data"]["curetotal"].ToString();
}
public string GetTime()
{
return jo["data"]["cachetime"].ToString();
}
}
}