解析Json.NET:"意外的令牌:StartObject"

Yuk*_*uya 10 c# json json.net

我正在解析JSON,我收到以下错误:

我正在使用Newtonsoft.Json.NET DLL.

读取字符串出错.意外的令牌:StartObject.路径'[0]',第1行,第2位.

这是我的代码:

public static List<string> GetPluginByCategory(string category)
    {
        var wc = new WebClient();
        var json = wc.DownloadString("http://api.bukget.org/api2/bukkit/category/" + category);
        var list = JsonConvert.DeserializeObject<List<string>>(json);
        return list;
    }
Run Code Online (Sandbox Code Playgroud)

category可以是以下字符串之一:

["管理工具","反悲伤工具","聊天相关","开发者工具","经济","修复","乐趣","一般","信息","力学","杂项" ,"角色扮演","传送","网站管理","世界编辑与管理","世界发电机"

编辑:这是我得到的回应:

 [{"description": "Stop users swearing\n", "name": "a5h73y", "plugname": "NoSwear"}, {"description": "Be sure that your server rules are read and accepted!", "name": "acceptdarules", "plugname": "AcceptDaRules"}]
Run Code Online (Sandbox Code Playgroud)

有谁知道为什么它不起作用?以前用过:/.

L.B*_*L.B 22

你的json是一个复杂对象的数组,而不是一个字符串数组.试试这个(测试):

WebClient wc = new WebClient();
string json = wc.DownloadString("http://api.bukget.org/api2/bukkit/category/Teleportation");

var items = JsonConvert.DeserializeObject<List<MyItem>>(json);

public class MyItem
{
    public string description;
    public string name;
    public string plugname;
}
Run Code Online (Sandbox Code Playgroud)

编辑

WebClient wc = new WebClient();
var json = wc.DownloadString("http://api.bukget.org/api2/bukkit/plugin/aboot");

dynamic dynObj = JsonConvert.DeserializeObject(json);
Console.WriteLine("{0} {1}", dynObj.plugname,dynObj.link);
foreach (var version in dynObj.versions)
{
    var dt = new DateTime(1970, 1, 1).AddSeconds((int)version.date);
    Console.WriteLine("\t{0} {1} {2}",version.version, version.download, dt);
}
Run Code Online (Sandbox Code Playgroud)