問題
JSONとして正しい構文はどれか。
- A
["Lodging": [ { "type":hotel, "location":B01 "contact":446-301-12847 } ] ]
- B
{ "truck": [ { "type": "Ford", "color": "red", "year": "1998" } ] }
- C
["car":{ "type": "Ford", "color": "red", "year": "1998", } ]
- D
[ "subject":{ "title": "Art History" "listing": "elective" "session": "Spring" } ]
正解:B
理由
キーと文字列値を二重引用符で囲み、オブジェクトは波括弧、配列は角括弧を対応させる。メンバーをカンマで区切り、末尾へ余分なカンマを置かない。
選択肢ごとの説明
- A.
["Lodging": [ { "type":hotel, "location":B01 "contact":446-301-12847 } ] ]
配列へLodgingというキーを直接置いている。hotelやB01が引用符で囲まれず、区切りにも不足がある。
- B.
{ "truck": [ { "type": "Ford", "color": "red", "year": "1998" } ] }
truckの値は配列で、内部のオブジェクトに正しいキーと文字列値、区切り、括弧がある。
- C.
["car":{ "type": "Ford", "color": "red", "year": "1998", } ]
配列へcarというキーを直接置き、最後のメンバーにも余分なカンマがある。
- D.
[ "subject":{ "title": "Art History" "listing": "elective" "session": "Spring" } ]
メンバー間のカンマがない。配列へsubjectのキーとオブジェクトを直接置く構造も不正である。