0% found this document useful (0 votes)
16 views

Lecture 8

Uploaded by

usamashahid7070
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views

Lecture 8

Uploaded by

usamashahid7070
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 32

Web Services

Road Map

HTTPS THREAD AND


JASON PARSING
NETWORKING PARALELLISM
First Design a Screen/UI for Earth Quack
App

?
Links for Choosing Design
https://developer.android.com/design

https://dribbble.com/tags/android
Application Programming Interface(API)
API is the acronym for Application Programming Interface, which is a
software intermediary that allows two applications to talk to each other.
Each time you use an app like Facebook, send an instant message, or
check the weather on your phone, you’re using an API
Example:
◦ When you use an application on your mobile phone, the application connects to
the Internet and sends data to a server. The server then retrieves that data,
interprets it, performs the necessary actions and sends it back to your phone. The
application then interprets that data and presents you with the information you
wanted in a readable way. This is what an API is - all of this happens via API.
Demonstration of API
https://earthquake.usgs.gov/fdsnws/event/1/

Programmable Web API Directory: http://www.programmableweb.com/apis/directory


Google APIs Explorer: https://developers.google.com/apis-explorer/#p/
Data.gov: http://data.gov
Understand the feeds type https://earthquake.usgs.gov/earthquakes/feed/v1.0/index.php
Exploring data on website
Link for API request:
◦ https://earthquake.usgs.gov/fdsnws/event/1/

API Documentation Understanding


https://earthquake.usgs.gov/fdsnws/event/1/[METHOD[?PARAMETERS]]
Query to submit a data request. See the parameters section for supported url
parameters.
https://earthquake.usgs.gov/fdsnws/event/1/query?format=geojson&starttime=2014-01-01&end
time=2014-01-02
https://earthquake.usgs.gov/fdsnws/event/1/query?format=xml&starttime=2014-01-01&endtim
e=2014-01-02&minmagnitude=5

Practice:
◦ https://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/4.5_week.geojson
Select the Perspectives

Load the CSV


on APP!
Embedded Data Issues
Update the data every time
Republish an app.
Quiz
https://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/4.5_week.geojson
Answer
JASON PARSING
What is JSON
JSON is an acronym for JavaScript Object Notation, is an open standard format, which is
lightweight and text-based, designed explicitly for human-readable data interchange. It is a
language-independent data format. It supports almost every kind of language, framework,
and library.
❖JSON is an open standard for exchanging data on the web. It supports data structures like
objects and arrays. So, it is easy to write and read data from JSON.
❖In JSON, data is represented in key-value pairs, and curly braces hold objects, where a colon is
followed after each name. The comma is used to separate key-value pairs. Square brackets are
used to hold arrays, where each value is comma-separated.
Why do we use JSON?
Since JSON is an easy-to-use, lightweight language data interchange format in comparison to other
available options, it can be used for API integration. Following are the advantages of JSON:
Less Verbose: In contrast to XML, JSON follows a compact style to improve its users' readability. While
working with a complex system, JSON tends to make substantial enhancements.
Faster: The JSON parsing process is faster than that of the XML because the DOM manipulation library
in XML requires extra memory for handling large XML files. However, JSON requires less data that
ultimately results in reducing the cost and increasing the parsing speed.
Readable: The JSON structure is easily readable and straightforward. Regardless of the programming
language that you are using, you can easily map the domain objects.
Structured Data: In JSON, a map data structure is used, whereas XML follows a tree structure. The
key-value pairs limit the task but facilitate the predictive and easily understandable model
JSON Data Types
Data types
JSON Objects
In JSON, objects refer to dictionaries, which are enclosed in
curly brackets, i.e., { }. These objects are written in
key/value pairs, where the key has to be a string and values
have to be a valid JSON data type such as string, number,
object, Boolean or null. Here the key and values are
separated by a colon, and a comma separates each key/value
pair.
◦{"name" : "Jack", "employeeid" : 001, "present" : false}
Data types
JSON Arrays
In JSON, arrays can be
understood as a list of objects,
which are mainly enclosed in
square brackets [ ]. An array value
can be a string, number, object,
array, boolean or null.
In the example, the object "Pizza"
is an array. It contains five
objects, i.e., PizzaName, Base,
Toppings, Spicy, and Veg.
Data types
Nesting
Nesting involves keeping the arrays
and objects inside of each other. We
can put the arrays inside objects,
objects inside arrays, arrays inside
arrays, etc. We can say that json file
is a big object with lots of objects and
arrays inside.
In the code, the song starts with a
curly bracket. Therefore, a song is an
object. It contains three key-value
pairs wherein title, artist and
musicians are the keys.'
Practice
Mark Quiz
https://gist.github.com/udacityandroid/919553548886a18a7c14e1e21f18ae5b
Answer
JSON - Parsing
Lets Query
https://earthquake.usgs.gov/fdsnws/event/1/query?format=geojson&starttime=2014-01-01&e
ndtime=2014-01-02
Complete Code Link
https://github.com/udacity/ud843-QuakeReport/blob/lesson-two/app/src/main/java/com/exa
mple/android/quakereport/EarthquakeActivity.java

You might also like