《Android移动应用基础教程》(Android(安卓)Studio)(第二版)黑马教程 课后题答案 第11章
16lz
2021-12-04
《Android移动应用基础教程》(Android Studio)(第二版)黑马教程 课后题答案 第11章——网络与数据处理
一、填空题
-
URLConnection
-
WebKit
-
JSONObject
二、判断题
- 对 2、对 3、对 4、对 5、对 6、错
三、选择题
- ABCD 2、ABD
四、简答题
- 简述使用HttpURLConnection 访问网络的步骤。
答:使用HttpURLConnection访问网络的步骤如下:
(1) 创建URL对象。
(2) 调用URL对象的openConnection()方法获取HttpURLConnection对象。
(3) 调用setRequestMethod()方法设置http请求的方式。
(4) 通过setConnectTimeout()方法设置连接的超时时间。
(5) 调用getInputStream()方法获取服务器返回的输入流。
(6) 最后调用disconnect()方法关闭http连接。
五、编程题
- 请写出使用JSONArray类解析JSON数据的主要逻辑代码。JSON数据如下所示。
[{“name”:“LiLi”,“score”:“95”},{“name”:“LiLei”,“score”:“99”},
{“name”:“王小明”,“score”:“100”},{“name”:“LiLei”,“score”:“89”}]
答:使用JSONArray类解析JSON数据的逻辑代码如下:
public void getJson(){String json = "[" + "{" +"\"" + "name" + "\"" + ":" +"\"" + "LiLi" + "\"" +","+"\"" + "score" + "\"" +":" + "\"" + "95" + "\""+"}," + "{" + "\"" +"name" + "\"" + ":" + "\"" +"LiLei" + "\"" + ","+"\"" +"score" + "\"" + ":" + "\"" +"99" + "\""+ "}," + "{" + "\"" +"name" + "\"" + ":" + "\"" +"李小明" +"\"" + ","+"\"" + "score" +"\"" + ":" + "\"" + "100" +"\""+ "}," + "{" + "\"" +"name" + "\"" + ":" + "\"" +"王小敏" +"\"" + ","+"\"" + "score" +"\"" + ":" + "\"" + "89" +"\""+ "}"+ "]";JSONArray jsonArray = null;try { jsonArray = new JSONArray(json); for(int i = 0; i
更多相关文章
- cocos2d-x学习笔记06:如何将win32移植到android
- Android(安卓)Activity 简介
- android使用属性动画代替补间动画
- Android(安卓)Shape Drawable 静态使用和动态使用(圆角,渐变实现)
- 2011Android技术面试整理附有详细答案(包括百度、新浪、中科软等
- 使用GDB调试Android(安卓)NDK native(C/C++)程序
- Android中ViewFlipper的使用
- Android的消息机制————读书笔记
- android介绍以及学习方法