반응형
json.js와 json2.js의 차이점
누군가 2 JSON 파서의 차이점을 말할 수 있습니까?
https://github.com/douglascrockford/JSON-js/blob/master/json.js
https://github.com/douglascrockford/JSON-js/blob/master/json2.js
2007-04-13의 JSON 파일이 있습니다 (와 같은 메서드가 있습니다 parseJSON
). 새 버전에서는 이러한 방법이 표시되지 않습니다.
그들의 코드에서 :
// Augment the basic prototypes if they have not already been augmented.
// These forms are obsolete. It is recommended that JSON.stringify and
// JSON.parse be used instead.
if (!Object.prototype.toJSONString) {
Object.prototype.toJSONString = function (filter) {
return JSON.stringify(this, filter);
};
Object.prototype.parseJSON = function (filter) {
return JSON.parse(this, filter);
};
}
parseJSON은 더 이상 사용되지 않으므로 새 버전 (json2)은 더 이상 사용하지 않습니다. 그러나 코드가 parseJSON
많이 사용 되는 경우이 코드를 어딘가에 추가하여 다시 작동 할 수 있습니다.
Object.prototype.parseJSON = function (filter) {
return JSON.parse(this, filter);
};
여기에서 인용 :
"JSON2.js-작년 말 Crockford는 기존 API를 대체하는 새 버전의 JSON API를 조용히 출시했습니다. 중요한 차이점은 단일 기본 개체를 사용한다는 점입니다."
또한 json2가 json2007과 다르게 배열을 문자열 화 한 것을 발견했습니다.
json2007에서 :
var array = [];
array[1] = "apple";
array[2] = "orange";
alert(array.toJSONString()); // Output: ["apple", "orange"].
json2에서 :
var array = [];
array[1] = "apple";
array[2] = "orange";
alert(JSON.stringify(array)); // Output: [null, "apple", "orange"].
참고 URL : https://stackoverflow.com/questions/552135/difference-between-json-js-and-json2-js
반응형
'program tip' 카테고리의 다른 글
동기 XMLHttpRequest를 사용하는 이유가 있습니까? (0) | 2020.09.17 |
---|---|
Angular2의 프로덕션 모드와 개발 모드의 차이점은 무엇입니까? (0) | 2020.09.17 |
Ruby에서 문자열을 주어진 길이의 덩어리로 자르는 가장 좋은 방법은 무엇입니까? (0) | 2020.09.16 |
Lazy I / O의 나쁜 점은 무엇입니까? (0) | 2020.09.16 |
문자열이 null인지 비어 있는지 확인하는 가장 쉬운 방법 (0) | 2020.09.16 |