Hardware Reference
In-Depth Information
JSON represents each cell of the table as a name-value pair. Each line is a comma-separated list of pairs, enclosed in
curly braces. The whole table is a comma-separated list of lists, like so:
[{"Address":1,"Location":"kitchen","Last read":"12:30:00 PM","value":60},
{"Address":2,"Location":"living room","Last read":"05:40:00 AM","value":54},
{"Address":3,"Location":"bathroom","Last read":"01:15:00 AM","value":23},
{"Address":4,"Location":"bedroom","Last read":"09:25:00 AM","value":18},
{"Address":5,"Location":"hallway","Last read":"06:20:00 AM","value":3}]
This way of formatting data is relatively simple. The punctuation that separates each element is just a single character,
so you can scan through it one character at a time and know when you're done with each element. Because it's text,
it's human-readable as well as machine-readable. Spaces, newlines, and tabs aren't considered part of the structure of
JSON, so you can reformat it for easier reading like so:
The advantage of a data interchange format like JSON
is that it's lightweight, meaning there aren't a lot of extra
bytes needed to structure the information you want to
send. It gives you more power than a simple list but is still
efficient to send from a server to a client. You can send
JSON as the body of an HTTP request, and as long as
there's a program on the client that can parse it, you've got
a quick way to exchange complex data.
[
{
"Address":1,
"Location":"kitchen",
"Last read":"12:30:00 PM",
"value":60
},
{
"Address":2,
"Location":"living room",
"Last read":"05:40:00 AM",
"value":54
},
{
"Address":3,
"Location":"bathroom",
"Last read":"01:15:00 AM",
"value":23
},
{
"Address":4,
"Location":"bedroom",
"Last read":"09:25:00 AM",
"value":18
},
{
"Address":5,
"Location":"hallway",
"Last read":"06:20:00 AM",
"value":3
}
]
When you've got something more complex to represent,
you need a markup language. Markup languages provide
a way to describe the structure of a text document in
detail. Markup languages divide data into the content and
the markup , a series of descriptive tags for organizing
the content. The content is what you want to present; the
markup describes how to present the content, what to do
with it—and in some cases—how to interpret it.
Markup tags are typically strings of text separated from
the content by a special pair of punctuation marks. You've
seen them frequently in HTML:
<title> this is the document title</title>
If a tag has any attributes, they go inside the tag brackets
as well:
<a href="www.example.com>A link</a>
Strict markup languages like XML always expect that
every opening tag has a closing tag. Markup languages
are strict in their formatting because they're designed to
be machine-readable. A computer program can't assume
where you meant to put a closing tag, so it will just keep
looking until it finds the next one. If it finds a second
opening tag before it gets to a closing tag, it gets confused.
 
Search WWH ::




Custom Search