programing

json.js와 json2.js의 차이점

minxs 2023. 3. 7. 22:01
반응형

json.js와 json2.js의 차이점

두 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);
    };
}

parseJ인가?SON은 더 이상 사용되지 않으므로 새 버전(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

반응형