Java Reference
In-Depth Information
}
draggedEl.parentNode.removeChild(draggedEl);
this.appendChild(draggedEl);
this.className = "";
After you remove the dragged element from its parent and append it to the drop target, you reach into
your data object and alert its message to the user:
alert(data.message);
}
This technique of using JSON to store object data is useful in a variety of scenarios. In the next
chapter, you use the same technique to store object data directly in the browser.
summarY
In this chapter, you looked at JSON, a text format for storing and transmitting objects, arrays, and
simple values. Let's look at some of the things discussed in this chapter:
Serialization is the process of translating objects and values into a string representation of
those objects and values.
The web used to use XML for storing and transmitting JavaScript data, but JSON is now the
format of choice.
JSON is not JavaScript, but a subset of JavaScript. Its syntax looks similar, but key differ-
ences exist between the two. For one, JSON does not have variables or functions. It is simply
a data format.
JSON strings must be surrounded by double quotes. Single quotes result in an error.
Numbers, booleans, and null appear as literal values in JSON.
JSON objects look very much like JavaScript object literals except their properties are strings
and there are no trailing semicolons.
JSON arrays are almost identical to JavaScript array literals, but they do not have a trailing
semicolon.
You serialize JavaScript objects, arrays, and values using the JSON object's stringify()
method.
You parse JSON text into a JavaScript object or value using JSON.parse() .
In the next chapter, you look at how to store data in and for the browser using local storage and
cookies.
 
Search WWH ::




Custom Search