嗨嗨!我是Winnie溫尼~
前面幾個章節,我們學到了用[]包覆住的是陣列,以及用{}包覆住的物件,用來記錄詳細的細部資訊,而陣列與物件在實戰中他們是很常一起出現的喔~!
使用時機:
let myFamily = [me,dad,mom,cat]
以物件紀錄
let me = {
name:"Winnie",
age:18,
}
let dad = {
name:"Tony",
age:52,
}
let Mom = {
name:"Jenny",
age:50,
}
let cat = {
name:"snow",
age:2,
}
以陣列與物件紀錄
let myFamily = [
me{
name:"Winnie",
age:18,
},
dad{
name:"Tony",
age:52,
},
mom{
name:"Jenny",
age:50,
},
cat{
name:"snow",
age:2,
}
]
全名為JavaScript Object Notation,是程式語言的資料格式,屬性會被雙引號""包覆,多使用於JavaScript、Java、Node.js、C#。
例:
{
"firstName": "John",
"lastName": "Smith",
"sex": "male",
"age": 25,
"address":
{
"streetAddress": "21 2nd Street",
"city": "New York",
"state": "NY",
"postalCode": "10021"
},
"phoneNumber":
[
{
"type": "home",
"number": "212 555-1234"
},
{
"type": "fax",
"number": "646 555-4567"
}
]
}
JSON格式的檔案類型在各開放平臺的資料庫會很常見,檢視線上的JSON格式建議可以安裝Chrome套件JSON Formatter以利閱讀。
例:顯著有感地震報告
records: {
datasetDescription: "地震報告",
earthquake: [
{
earthquakeNo: 111146,
reportType: "地震報告",
reportColor: "綠色",
reportContent: "09/27-19:11臺東縣東河鄉發生規模4.2有感地震,最大震度臺東縣東河4級。",
reportImageURI:"https://scweb.cwb.gov.tw/webdata/OLDEQ/202209/2022092719110942146_H.png",
reportRemark: "本報告係中央氣象局地震觀測網即時地震資料地震速報之結果。",
web: "https://scweb.cwb.gov.tw/zh-tw/earthquake/details/2022092719110942146",
shakemapImageURI:"https://scweb.cwb.gov.tw/webdata/drawTrace/plotContour/2022/2022146i.png",
earthquakeInfo: {
originTime: "2022-09-27 19:11:09",
source: "中央氣象局",
depth: {
value: 8.8,
unit: "公里"
},
epiCenter: {
location: "臺東縣政府北北東方 22.4 公里 (位於臺東縣東河鄉)",
epiCenterLat: {
value: 22.94,
unit: "度"
},
epiCenterLon: {
unit: "度",
value: 121.24
}
}
]
}
新手上路,如文章有錯誤或需修正之處,懇請大家多多指教!
那麼,我們明天見囉~