2025年春江苏开放大学.NET架构与项目开发实训第二次作业答案
一、单选题
1、当json字符串调用
voidclient_DownloadStringcompleted(objectsender,DownloadStringCompletedEventArgse)
{
weatherClassw=deserialize(e.Result)
showMsg(e.Result);
}
结果是什么?
A、json对象
B、json字符串
C、以上答案都不对
D、xml字符串
正确答案:B
2、Stringserialize(Tobj)
{
_____
MemoryStreamms=newMemoryStream();
json.WriteObject(ms,obj)
Strings=Encoding.UTF8.GetString(ms.ToArray());
returns;
}
序列化函数serialize缺少的语句是:
A、以上说法都不对
B、DataContractSerializerjson=newDataContractSeriaDataContractSerializerlizer(typeof(WeatherClass));
C、XmlSerializerxml=newXmlSerializer(typeof(WeatherClass));
D、DataContractSerializerjson=DataContractSerializer(typeof(WeatherClass));
正确答案:B
3、当json字符串调用
voidclient_DownloadStringcompleted(objectsender,DownloadStringCompletedEventArgse)
{
weatherClassw=deserialize(e.Result);
showMsg(w.Tostring());
}
结果是什么?
A、以上都不对
B、json反序列化结果
C、json字符串
D、xml字符串
正确答案:B
4、下面程序下载的字符串:
try
{
WebClientclient=newWebClient();
client.Encoding=Encoding.UTF8;
client.DownloadStringCompleted+=client_DownloadStringCompleted;
Uriuri=newUri(“”,UriKind.Absolute);
client.DownloadStringAsync(uri);
msg.Text=”OK”;
}
catch(Exceptionexp){msg.Text=exp.Message;}
在执行client.DownloadStringAsync(uri)后
A、程序等待服务器响应,然后显示msg.Text=”OK”;
B、程序不等待服务器响应,就显示msg.Text=”OK”;
C、程序client.DownloadStringCompleted+=client_DownloadStringCompleted有错误
D、以上说法都不对
正确答案:B
5、Stringserialize(WeatherClassw)
{
_____
MemoryStreamms=newMemoryStream();
xml.Serialize(ms,w);
Strings=Encoding.UTF8.GetString(ms.ToArray());
returns;
}
序列化函数serialize缺少的语句是:
A、XmlSerializerxml=XmlSerializer(typeof(WeatherClass));
B、以上说法都不对
C、XmlSerializerxml=newXmlSerializer(typeof(WeatherClass));
D、XmlSerializerxml=XmlSerializer(WeatherClass);
正确答案:C
6、Tdeserialize(Strings)
{
XmlSerializerxml=newXmlSerializer(typeof(T));
byte[]buf=Encoding.UTF8.GetBytes(s);
MemoryStreamms=newMemoryStream(buf);
Tobj=(T)xml.Deserialize(ms);
returnobj;
}
把字符串s反序列化成Weather对象,那么正确的调用方法是:
A、Weatherw=(Weather)deserialize(s);
B