JSON
JSON是一种轻量级的数据交换格式,主要用于跟服务器进行交换数据。
JSON数据格式应用非常广泛,在APP开发中,大多数据端返回的接口数据都是采用JSON数据格式的。
JSON的两种数据格式
JSONObject和JSONArray,JSONObject表示JSON对象,而JSONArray表示的则是数组。
运用HttpURLConnection+JSON获取天气预报数据信息
代码如下
Activity中xml代码
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.lenovo.liu.weatherdemo.MainActivity">
<EditText
android:id="@+id/weath_city"
android:layout_width="match_parent"
android:layout_height="50dp"
android:hint="请输入所要查询的城市" />
<Button
android:id="@+id/weather_btn"
android:layout_width="180dp"
android:layout_height="60dp"
android:layout_gravity="center"
android:text="查询" />
<TextView