Web请求和流,不在[] c#之间读取

时间:2016-06-03 13:22:26

标签: c# json xbmc

我正在尝试从webrequest中读取json字符串。 我使用HttpWebRequest,因为服务器需要身份验证。

我可以读取答案字符串,但[]。

之间的数据除外

答案应如下所示:

{
    "id": 1,
    "jsonrpc": "2.0",
    "result": [{
        "playerid": 0,
        "type": "video"
    }]
}

但只是这样:

{
    "id": 1,
    "jsonrpc": "2.0",
    "result": []
}

json由Kodi / xbmc生成

我做错了什么?

static void Main(string[] args) {
    string Url = @" http://192.168.1.118:8080/jsonrpc?request={""jsonrpc"": ""2.0"", ""method"": ""Player.GetActivePlayers"", ""id"": 1} ";

    string credentials = "user:passwd";
    HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(Url);

    request.Headers.Add("Authorization", "Basic " + Convert.ToBase64String(Encoding.UTF8.GetBytes(credentials)));
    request.PreAuthenticate = true;
    HttpWebResponse response = (HttpWebResponse)request.GetResponse();
    Stream resStream = response.GetResponseStream();

    StreamReader reader = new StreamReader(resStream);
    string text = reader.ReadToEnd();

    Console.WriteLine(text);
    Console.ReadLine();
}

0 个答案:

没有答案