JSON 數據使用方法

當同一個模板需要替換不同的數據顯示的時候,如果數據量大點,用json很方便。

json對象:

var JSONObject= {
"name":"Bill Gates",
"street":"Fifth Avenue New York 666",
"age":56,
"phone":"555 1234567"};

JSONObject.name = "Bill Gates"


json數組:

var employees = [
{ "firstName":"Bill" , "lastName":"Gates" },
{ "firstName":"George" , "lastName":"Bush" },
{ "firstName":"Thomas" , "lastName": "Carter" }
];

employees[0].firstname="Bill"

employees[1].lastname="Bush"

多個數組:

var options = {
		"question" :[
			{	
				"title":"1.劇中Amy對Raj說Cop a feel 的意思是?",
				"option1":"抓住感覺",
				"option2":"像個警察",
				"option3":"揩油,佔便宜",
				"option4":"受到侮辱",
				"correct":"3"
			},
			{
				"title":"2.看着他一臉驚愕的表情,out of the park表達了什麼?",
				"option1":"走出公園",
				"option2":"幹得漂亮",
				"option3":"停在外面",
				"option4":"公園門票賣光了",
				"correct":"2"
			},
			{
				"title":"3.face the music 怎麼翻譯才能配上他們的表情?",
				"option1":"面對音樂",
				"option2":"正視藝術",
				"option3":"看到樂譜",
				"option4":"承擔責任",
				"correct":"4"
			}],
		result:[
			{
				"title":"美劇俚語翻譯優秀",
				"content":"你是字幕界的驕傲,你是地道美劇迷,你的詞彙量超強,這是留美旅遊的大殺器!這麼拽的英語,證明你對美劇的熱愛!把你的美劇推薦分享給朋友,也把這驕傲的成績分享給朋友吧!"
			},
			{
				"title":"美劇俚語翻譯良好",
				"content":"你對美劇裏的俚語有一定的瞭解,知道一些美國俚語的用法,再接再厲哦,分享給朋友,看看他們答幾分?"
			},
			{
				"title":"美劇俚語翻譯不及格",
				"content":"親,允許你重考一次!"
			},
			{
				"title":"建議放棄美劇!!",
				"content":""
			}
		]
		};

options.question[0].title="1.劇中Amy對Raj說Cop a feel 的意思是?"

options.result[1].content="你對美劇裏的俚語有一定的瞭解,知道一些美國俚語的用法,再接再厲哦,分享給朋友,看看他們答幾分?"

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章