What's the difference between Javascript Object and JSON object
有人能举个例子告诉我JavaScript对象和JSON对象之间的区别吗?
Javascript object is a data type in Javascript-it makes only sense in Javascript.经常看到一个Javascript object literal like this:
1 2 3 4 | var obj = { a: 1, b: 2 }; |
一条JSON弦乐是一种数据交换格式——它比一组特征格式化了一种特别的方式(以不同的程序顺序与其他程序进行通信)更为重要。因为这个,它可能存在于Javascript内,或者在另一种语言或简单存储在数据库或文本文件中。
The above Javascript object can be represented in the JSON format in Javascript like this:
1 | var json = '{"a": 1,"b": 2 }'; |
Or in C 35;like this:
1 | string json ="{ "a": 1, "b": 2 }"; |
你可以看到,JSON简单地储存在弦乐里。为了使它使用,JSON弦乐可以在任何语言中产生一个对象。因为JSON Format mimimics Javascript's object literal syntax,Javascript makes the parsing process easy:
1 | var obj = eval('(' + json + ')'); |
尽管你是典型的看到:
1 | var obj = JSON.parse(json); // for security reasons |
Note that JSON is limited in that it cannot store functions-the only values it can contain are:
- 文学对象
- 阿雷斯
- 号码
- 布尔昂
- 弦乐
- 努尔
json is a text representation of a Javscript object.在Javascript note(hence the name-Javascript object note=>json)中,它是一个有效的文学对象。
如果你想"比较"两个对象,将文本与对象进行比较,然后比较关键和价值。
Some examples of objects to/from text:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | // Create obj using an object literal var obj = {key: 'value'}; // Convert to text using JSON.stringify var text = JSON.stringify(obj); // Show the value of text alert( text ); // {"key":"value"} // Create a new object from text var newObj = JSON.parse(text); // javascript object // Show the text version of newObj alert(JSON.stringify(newObj)); // {"key":"value"} // Use text as code var newObj2 = eval('(' + text + ')'); // It is indeed a string literal alert(JSON.stringify(newObj2)); // {"key":"value"} |
如果你想比较两个对象,从JSON到Objects(如果他们是JSON在第一个位置)然后做类似的事情:
ZZU1
JSON stands for"Javascript object notication."基本上,JSON是Javascript,但仅限于填写一个数据对象。通过执行一个JSON Object,你在记忆中的"载荷"数据。Javascript是一幅大图片,加上代码的附加线条来操纵对象或做其他种类的研究。
a JSON Example would be this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | { "glossary": { "title":"example glossary", "GlossDiv": { "title":"S", "GlossList": { "GlossEntry": { "ID":"SGML", "SortAs":"SGML", "GlossTerm":"Standard Generalized Markup Language", "Acronym":"SGML", "Abbrev":"ISO 8879:1986", "GlossDef": { "para":"A meta-markup language, used to create markup languages such as DocBook.", "GlossSeeAlso": ["GML","XML"] }, "GlossSee":"markup" } } } } } |
a Javascript example would be this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | var Glossary = { "glossary": { "title":"example glossary", "GlossDiv": { "title":"S", "GlossList": { "GlossEntry": { "ID":"SGML", "SortAs":"SGML", "GlossTerm":"Standard Generalized Markup Language", "Acronym":"SGML", "Abbrev":"ISO 8879:1986", "GlossDef": { "para":"A meta-markup language, used to create markup languages such as DocBook.", "GlossSeeAlso": ["GML","XML"] }, "GlossSee":"markup" } } } } } |
Notice the var glossary=in the javascript?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | var object = { name:"John", profession:"blogger" }; alert(object.name);//John alert(typeof(object));//Object alert(object);//[object Object] var json = JSON.stringify(object); alert(json.name);//undefined alert(typeof(json));//string alert(json);//{"name":"John","profession":"blogger"} |
首先,一个javascript就像其他对象在面向对象的编程中。
而正如罗伯格所说的,杰森是一个有效的文学对象,在贾瓦斯克里普评分。但不准确According to a Javascript book it says this is an object defined by using object notation:
1 2 3 4 | var newObject = { prop1 : true, showMessage : function (msg) {alert(msg)} }; |
According to Json in Javascript,
JSON是Javascript对象文字的一个辅助符号。
你可能还想考虑看这条链接