Last active
August 29, 2015 14:27
-
-
Save clamytoe/51343bfafc7eb2580acd to your computer and use it in GitHub Desktop.
HKUSTx: COMP107x Introduction to Mobile Application Development using Android
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"# Exercise: Handling JSON in Android\n", | |
"---\n", | |
"## Objectives\n", | |
"\n", | |
"In this exercise you will learn about processing a JSON string, and the use of Gson library. At the end of this exercise you will be able to:\n", | |
"\n", | |
"* Learn to process a JSON string and map it into Java objects\n", | |
"* Use the Google Gson library to process a JSON string into Java objects\n", | |
"\n", | |
"## Introduction\n", | |
"\n", | |
"This project is the first step in understanding how a client-server communication can be implemented in an Android app. We will learn to process a JSON string and map it into a list of Java objects to be used for constructing list items for a ListView.\n", | |
"\n", | |
"## Textual Instructions\n", | |
"---\n", | |
"### Step 1: Examining the Project Files\n", | |
"\n", | |
"1. Download the [ChatClientJson.zip](http://w02.hkvu.hk/edX/COMP107x/w5/ChatClientJson.zip) file, unzip it and import the project into Android Studio.\n", | |
"2. Open the **friend_item.xml** file.\n", | |
"3. Open the **Contacts.java** file and the **MyArrayAdapter.java** file.\n", | |
"4. Follow the video instructions.\n", | |
"\n", | |
"---\n", | |
"### Step 2: Updating the Contacts Activity\n", | |
"\n", | |
"1. Open the Contacts.java file and navigate to the processFriendInfo() method.\n", | |
"2. Replace the first // TODO comment with the following code.\n", | |
" GsonBuilder gsonBuilder = new GsonBuilder();\n", | |
" Gson gson = gsonBuilder.create();\n", | |
"3. Replace the second // TODO comment with the following code.\n", | |
" friendInfoList = new ArrayList<FriendInfo>();\n", | |
" friendInfoList = Arrays.asList(gson.fromJson(infoString, FriendInfo[].class));\n", | |
"\n", | |
"4. Run the app and see the result." | |
] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Python 2", | |
"language": "python", | |
"name": "python2" | |
}, | |
"language_info": { | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 2 | |
}, | |
"file_extension": ".py", | |
"mimetype": "text/x-python", | |
"name": "python", | |
"nbconvert_exporter": "python", | |
"pygments_lexer": "ipython2", | |
"version": "2.7.6" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 0 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment