我是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;
}
答案 0 :(得分:1)
尝试直接
var data = (RootObject)serializer.ReadObject(result);
没有var ms = new MemoryStream(
行。 ReadObject
接受Stream
作为输入,result
是Stream
。