Java Reference
In-Depth Information
The value
null
is also valid. These types and structures were chosen because
modern programming languages support them natively. For instance, Listing
10.3 shows a sample JSON object structure, named
Image
, as returned from
Yahoo! Web Services.
Listing 10.3
Sample JSON Object
{
"Image": {
"Width":123,
"Height":145,
"Title":"Java Duke Guitar",
"Thumbnail": {
"Url":
"http:\/\/sk1.yt-thm-a01.yimg.com\/image\/b6ece07210e09816",
"Height": 20,
"Width": 25
},
"IDs":[ 116, 943, 234, 38793 ]
}
}
This JSON data defines an
Object
(named
Image
) that contains two
Number
fields (named
Width
and
Height
), a
String
field (named
Title
), another
Object
(named
Thumbnail
), and an array (named
IDs
). The
Thumbnail
object
contains its own
String
and
Number
fields, and the
IDs
array contains a series of
Number
values.
Let's take a closer look at some Web services that are available publicly for you
to use in your applications. The two we'll discuss in this chapter, Yahoo! and
GeoNames, both support JSON for many of their services. In the next section,
we'll build an application that combines these two Web services to form a
mashup JavaFX application.
Yahoo! offers a large number of Web service APIs that you can use to create
your own applications; you can explore these Web services at
http://developer
.yahoo.com/everything.html.
Although the APIs all support XML as a return
type, a good number of them also provide JSON as an alternative (see
http://
onto the request URL, you can specify XML or JSON as the response data type.
Search WWH ::
Custom Search