ü通訊頻繁
ü資料量不大
練習用API(JSON)
JSON解析類別(GSON, Jackson, JSON.simple, JSONP, Fastjson)
GSON, Jackson, JSON.simple以及JSONP之速度→大文件(190MB)小文件(1KB)
8個bit=1byte=一個數字或一字母 (1KB=1024字母)
處理小的JSON文件→GSON
處理大的JSON文件→Jackson
兩者則→JSON.simple
================================
[Android Studio] 自動加入import
1. File → Settings→ Editor→ General→Auto Import → Java
2. 設定成:: Insert import on paste: All 選項全勾
參考文章:
https://litotom.com/2016/11/07/volley_open_data_json/
https://read01.com/zh-tw/E84e2M.html#.W0YFB9UzbIU
文章標籤
全站熱搜

// Request a string response from the provided URL. StringRequest stringRequest = new StringRequest(Request.Method.GET, url, new Response.Listener<String>() { @Override public void onResponse(String response) { // Display the first 500 characters of the response string. Log.i("msg","Response is: "+ response.substring(0,500)); progressDialog.dismiss(); } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { Log.i("error","That didn't work!"); progressDialog.dismiss(); } }); // Add the request to the RequestQueue. queue.add(stringRequest); progressDialog = new ProgressDialog(context); progressDialog.setMessage("Fetching The File...."); progressDialog.show();
https://stackoverflow.com/questions/18513272/android-studio-volley API 23 若不能同步 改↓ implementation 'com.android.volley:volley:1.1.0'
import static android.content.ContentValues.TAG;
void getData() { String urlParkingArea = "http://data.taipei/opendata/datalist/apiAccess?scope=resourceAquire&rid=a880adf3-d574-430a-8e29-3192a41897a5"; RequestQueue mQueue = Volley.newRequestQueue(getApplicationContext()); JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.GET, urlParkingArea, null, new Response.Listener<JSONObject>(){ @Override public void onResponse(JSONObject response) { try { parserJson(response); }catch (Exception e){ e.printStackTrace(); } } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { error.printStackTrace(); } }) ; mQueue.add(jsonObjectRequest ); }