JSON stands for JavaScript Object Notation. It is a lightweight data-interchange format and is very easy to use. This recipe shows you how to display the prices of Precious Metals from a JSON file.
Copy the full code of this recipe from the code/04/json-content
sources folder. You can launch this code using the URL http://localhost:8080/04/json-content/main.html
.
Create the
precious.json
file containing an array of the five precious metals. The name, symbol, and the intradayopen
,close
,high
, andlow
prices are also available, as shown in the following code:[ { "name": "Gold", "symbol": "Au", "price": { "open": 1642.46, "close": 1682.42, "high": 1699.66, "low": 1638.51 } }, { "name": "Silver", "symbol": "Ag", "price": { "open": 31.24, "close": 33.11, "high": 33.65, "low": 31.21 } }, { "name": "Platinum", "symbol": "Pt", "price": { "open": 1621.15, "close": 1623.87, "high": 1624.45, "low": 1620.98...