Subversion Repositories Applications.papyrus

Rev

Rev 1987 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1318 alexandre_ 1
/*
2
	Copyright (c) 2004-2006, The Dojo Foundation
3
	All Rights Reserved.
4
 
5
	Licensed under the Academic Free License version 2.1 or above OR the
6
	modified BSD license. For more information on Dojo licensing, see:
7
 
8
		http://dojotoolkit.org/community/licensing.shtml
9
*/
10
 
1422 alexandre_ 11
 
12
 
1318 alexandre_ 13
dojo.provide("dojo.json");
14
dojo.require("dojo.lang.func");
15
dojo.require("dojo.string.extras");
16
dojo.require("dojo.AdapterRegistry");
17
dojo.json = {jsonRegistry:new dojo.AdapterRegistry(), register:function (name, check, wrap, override) {
18
	dojo.json.jsonRegistry.register(name, check, wrap, override);
19
}, evalJson:function (json) {
20
	try {
21
		return eval("(" + json + ")");
22
	}
23
	catch (e) {
24
		dojo.debug(e);
25
		return json;
26
	}
27
}, serialize:function (o) {
28
	var objtype = typeof (o);
29
	if (objtype == "undefined") {
30
		return "undefined";
31
	} else {
32
		if ((objtype == "number") || (objtype == "boolean")) {
33
			return o + "";
34
		} else {
35
			if (o === null) {
36
				return "null";
37
			}
38
		}
39
	}
40
	if (objtype == "string") {
41
		return dojo.string.escapeString(o);
42
	}
43
	var me = arguments.callee;
44
	var newObj;
45
	if (typeof (o.__json__) == "function") {
46
		newObj = o.__json__();
47
		if (o !== newObj) {
48
			return me(newObj);
49
		}
50
	}
51
	if (typeof (o.json) == "function") {
52
		newObj = o.json();
53
		if (o !== newObj) {
54
			return me(newObj);
55
		}
56
	}
57
	if (objtype != "function" && typeof (o.length) == "number") {
58
		var res = [];
59
		for (var i = 0; i < o.length; i++) {
60
			var val = me(o[i]);
61
			if (typeof (val) != "string") {
62
				val = "undefined";
63
			}
64
			res.push(val);
65
		}
66
		return "[" + res.join(",") + "]";
67
	}
68
	try {
69
		window.o = o;
70
		newObj = dojo.json.jsonRegistry.match(o);
71
		return me(newObj);
72
	}
73
	catch (e) {
74
	}
75
	if (objtype == "function") {
76
		return null;
77
	}
78
	res = [];
79
	for (var k in o) {
80
		var useKey;
81
		if (typeof (k) == "number") {
82
			useKey = "\"" + k + "\"";
83
		} else {
84
			if (typeof (k) == "string") {
85
				useKey = dojo.string.escapeString(k);
86
			} else {
87
				continue;
88
			}
89
		}
90
		val = me(o[k]);
91
		if (typeof (val) != "string") {
92
			continue;
93
		}
94
		res.push(useKey + ":" + val);
95
	}
96
	return "{" + res.join(",") + "}";
97
}};
98