JSON(JavaScript Object Notation)是一種輕量級(jí)的數(shù)據(jù)交換格式,它基于JavaScript語言的語法,由鍵值對(duì)組成,并使用逗號(hào)將鍵值對(duì)分隔開來,最外層由花括號(hào)包圍,表示一個(gè)對(duì)象。
{ "name": "Peter", "age": 30, "address": { "street": "123 Main St", "city": "New York", "state": "NY", "zip": "10001" }, "hobbies": ["reading", "sports", "traveling"] }
每個(gè)鍵值對(duì)中,鍵必須是一個(gè)字符串,值可以是字符串、數(shù)字、布爾值、對(duì)象、數(shù)組或null。如果值為對(duì)象,則該對(duì)象必須符合JSON的格式;如果值為數(shù)組,則數(shù)組中的元素也必須符合JSON的格式。
對(duì)于復(fù)雜的JSON數(shù)據(jù),可以使用多層嵌套表示,用縮進(jìn)表示嵌套層次關(guān)系。
{ "name": "Peter", "age": 30, "address": { "street": "123 Main St", "city": "New York", "state": "NY", "zip": "10001" }, "hobbies": [ { "name": "reading", "level": "advanced" }, { "name": "sports", "level": "intermediate" }, { "name": "traveling", "level": "beginner" } ] }
使用JSON的格式可以方便地進(jìn)行數(shù)據(jù)交換和處理,以及在不同編程語言之間進(jìn)行數(shù)據(jù)轉(zhuǎn)換。