-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJSIL.JSON.js
More file actions
51 lines (39 loc) · 1.31 KB
/
Copy pathJSIL.JSON.js
File metadata and controls
51 lines (39 loc) · 1.31 KB
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
"use strict";
if (typeof (JSIL) === "undefined")
throw new Error("JSIL.Core required");
var $jsiljson = JSIL.DeclareAssembly("JSIL.JSON");
JSIL.DeclareNamespace("JSIL");
JSIL.DeclareNamespace("JSIL.JSON");
JSIL.JSON.MapObject = function (input) {
var result;
var mscorlib = JSIL.GetAssembly("mscorlib", true);
var tList = JSIL.GetTypeFromAssembly(
mscorlib, "System.Collections.Generic.List`1", [
JSIL.GetTypeFromAssembly(mscorlib, "System.Object", [], true)
], true
);
var tDictionary = JSIL.GetTypeFromAssembly(
mscorlib, "System.Collections.Generic.Dictionary`2", [
JSIL.GetTypeFromAssembly(mscorlib, "System.String", [], true),
JSIL.GetTypeFromAssembly(mscorlib, "System.Object", [], true)
], true
);
if (JSIL.IsArray(input)) {
result = JSIL.CreateInstanceOfType(tList);
for (var i = 0; i < input.length; i++)
result.Add(JSIL.JSON.MapObject(input[i]));
} else if (typeof (input) === "object") {
var result = JSIL.CreateInstanceOfType(tDictionary);
for (var k in input)
result.Add(k, JSIL.JSON.MapObject(input[k]));
} else if (typeof (input) === "number") {
result = input;
} else {
result = input;
}
return result;
};
JSIL.JSON.Parse = function (json) {
var parsed = JSON.parse(json);
return JSIL.JSON.MapObject(parsed);
};