일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | |||||
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |
Tags
- Struts
- Eclipse
- JSON
- Google Map
- WebLogic
- iBATIS
- Android
- ibsheet
- phonegap
- GPS
- 선택적조인
- PLSQL
- Ajax
- JDOM
- dock
- swingx
- node.js
- MySQL
- PHP
- jsr 296
- appspresso
- 전자정부프레임워크
- jQuery
- tomcat
- MFC
- rowspan
- oracle
- 가우스
- sencha touch
- Spring
Archives
- Today
- Total
Where The Streets Have No Name
Cross-browser JSON Serialization in JavaScript 본문
출처 : http://www.sitepoint.com/javascript-json-serialization/
/**
* Implements JSON stringify and parse functions
* v1.0
*
* By Craig Buckler, Optimalworks.net
*
* As featured on SitePoint.com
* Please use as you wish at your own risk.
*
* Usage:
*
* // serialize a JavaScript object to a JSON string
* var str = JSON.stringify(object);
*
* // de-serialize a JSON string to a JavaScript object
* var obj = JSON.parse(str);
*/
var JSON = JSON || {};
// implement JSON.stringify serialization
JSON.stringify = JSON.stringify || function (obj) {
var t = typeof (obj);
if (t != "object" || obj === null) {
// simple data type
if (t == "string") obj = '"'+obj+'"';
return String(obj);
}
else {
// recurse array or object
var n, v, json = [], arr = (obj && obj.constructor == Array);
for (n in obj) {
v = obj[n]; t = typeof(v);
if (t == "string") v = '"'+v+'"';
else if (t == "object" && v !== null) v = JSON.stringify(v);
json.push((arr ? "" : '"' + n + '":') + String(v));
}
return (arr ? "[" : "{") + String(json) + (arr ? "]" : "}");
}
};
// implement JSON.parse de-serialization
JSON.parse = JSON.parse || function (str) {
if (str === "") str = '""';
eval("var p=" + str + ";");
return p;
};