1.在javascript中创建一个新的 JavaScript 变量,然后将 JSON 格式的数据字符串直接赋值给它:
var people= { "programmers":[ "firstName:","Brett","astName:","MclaughLin"........ "firstName:","Jason","astName:","Hunter"........ ......... ], "authors":[ "firstName:","Isaac","astName:","Asimov"........ "firstName:","Tad","astName:","williams"........ ......... ] ....... //如果不是结尾,每次增加一个需要用,号和下一个进行分隔
}
访问Json数据:
people.programmers[0].astName;//访问programmers列表的第一个条目的姓氏
people.authors[1].astName // 访问authors列表的第二条目的姓氏 people.authors[3].astName // Undefined. This refers to the fourth entry, and there isn't one 有点像访问访问数组时长度越界了
修改Json数据:
people.programmers[0].astName="John"; //修改programmers列表的第一个条目的astName内容
Json转换成字符串: String newJSONtext = people.toJSONString();
对名为 myObject 的对象进行转换: String myObjectInJSON = myObject.toJSONString();