【发布时间】:2017-06-19 03:55:27
【问题描述】:
我正在尝试将 cat 事实添加到我的不和谐机器人(不相关)并且我使用的网站返回一个类似于这样的 json:
{
"facts": ["The fact is here"],
"success": "true"
}
网站是http://catfacts-api.appspot.com/api/facts 我只想将事实作为字符串来获取。
以下是我目前正在使用的,但当事实包含'"'时会搞砸
System.Net.WebClient wc = new System.Net.WebClient();
string thingy = wc.DownloadString("http://catfacts-api.appspot.com/api/facts");
string[] thingys = thingy.Split('"');
string fact = thingys[3];
【问题讨论】:
-
看看 Newtonsoft.Json 库。
-
使用
Netwonsoft.Json将您的 JSON 字符串反序列化为 C# 对象。另请查看json2csharp.com。