CS1503 C#参数1:无法转换为System.IO.Stream' to' char []'

时间:2017-03-08 08:30:35

标签: c#

我是C的新手,并且不理解上面标题中的错误,我的代码如下,但错误显示在第7行,(结果);

public async static Task<RootObject> GetSensor(bool on)
    {
        var http = new HttpClient();
        var response = await http.GetAsync("http://192.168.0.71/api/apikey/sensors");
        var result = await response.Content.ReadAsStreamAsync();
        var serializer = new DataContractJsonSerializer(typeof(RootObject));

        var ms = new MemoryStream(Encoding.UTF8.GetBytes(result));//result is where the error is generated
        var data = (RootObject)serializer.ReadObject(ms);
        return data;
    }

1 个答案:

答案 0 :(得分:1)

尝试直接

var data = (RootObject)serializer.ReadObject(result);

没有var ms = new MemoryStream(行。 ReadObject接受Stream作为输入,resultStream