헤르메스 LIFE

[JSON] 문자열을 JSON 변환, JSON 을 문자열 변환 본문

JSP&JavaScript&HTML

[JSON] 문자열을 JSON 변환, JSON 을 문자열 변환

헤르메스의날개 2021. 1. 26. 13:46
728x90

JSON.parse()를 사용하기 위해서는 Douglas Crockford가 만든 json2.js가 필요합니다. json2.js는 더글라스 크록포드가 JSON의 편리한 사용을 위해 만든 JSON API의 새버전입니다.

이 API에는 2개의 메서드가 들어있는데 JSON.stringify()와 JSON.parse() 입니다. JSON.stringify()는 JSON.parse()와는 완전히 반대로 JSON 객체를 주면 JSON 텍스트로 만들어서 줍니다.

출처 : johnresig.com/blog/the-state-of-json/

 

John Resig - The State of JSON

I wanted to pull together some of the recent events that have occurred, related to native JSON support within a web browser, that should be of importance to many web developers. This should serve as a sort-of follow-up to my previous post: Native JSON Supp

johnresig.com

JSON.stringify({name: "John", location: "Boston"});
// => '{"name":"John","location":"Boston"}'
JSON.parse('{"name":"John","location":"Boston"}');
// => {name: "John", location: "Boston"}

출처 : johnresig.com/blog/native-json-support-is-required/

 

John Resig - Native JSON Support is Required

There’s a JavaScript feature that I feel needs much more attention: Native JSON support in browsers. It’s something that should be a JavaScript language feature and yet no browser, or standards body, has defined, specified, or implemented what exactly

johnresig.com

// Object.prototype.toJSONString
var foo = { test: true, sample: "string" };
foo.toJSONString();
>> '{"test":true,"sample":"string"}'

// Array.prototype.toJSONString
var foo = [ true, "string", 5 ];
foo.toJSONString();
>> '[true,"string",5]'

// Boolean.prototype.toJSONString
5.toJSONString();
>> '5'

// String.prototype.toJSONString
"test".toJSONString();
>> '"test"'

// Number.prototype.toJSONString
true.toJSONString();
>> 'true'

// null
"null".parseJSON()
>> null

github.com/douglascrockford/JSON-js

 

douglascrockford/JSON-js

JSON in JavaScript. Contribute to douglascrockford/JSON-js development by creating an account on GitHub.

github.com

 

728x90