{infiniteZest}
// Articles. Tutorials. Utilities.
Home  |   Search  |   Login  
Categories Skip Navigation Links
New / All
AJAX
Apple
ASP.NET
.NET
Git
Google / Android
Python / IronPython
Miscellaneous
SQL Server
AJAX Source Viewer
View the source code of a Method from ASP.NET AJAX Library. Choose a method from the menu items above (Namespaces, Classes, or Methods).
Method '_serializeWithBuilder(object, stringBuilder, sort, prevObjects)'
Method: _serializeWithBuilder(object, stringBuilder, sort, prevObjects)
Method Full Name:     Sys$Serialization$JavaScriptSerializer$_serializeWithBuilder(object, stringBuilder, sort, prevObjects)
Class: JavaScriptSerializer
Namespace: Sys.Serialization
Source File: MicrosoftAjax.debug.js
1   Sys.Serialization.JavaScriptSerializer._serializeWithBuilder = function Sys$Serialization$JavaScriptSerializer$_serializeWithBuilder(object, stringBuilder, sort, prevObjects) {
2     var i;
3     switch (typeof object) {
4       case 'object':
5         if (object) {
6           if (prevObjects){
7             for( var j = 0; j < prevObjects.length; j++) {
8               if (prevObjects[j] === object) {
9                 throw Error.invalidOperation(Sys.Res.cannotSerializeObjectWithCycle);
10              }
11            }
12          }
13          else {
14            prevObjects = new Array();
15          }
16          try {
17            Array.add(prevObjects, object);
18            
19            if (Number.isInstanceOfType(object)){
20              Sys.Serialization.JavaScriptSerializer._serializeNumberWithBuilder(object, stringBuilder);
21            }
22            else if (Boolean.isInstanceOfType(object)){
23              Sys.Serialization.JavaScriptSerializer._serializeBooleanWithBuilder(object, stringBuilder);
24            }
25            else if (String.isInstanceOfType(object)){
26              Sys.Serialization.JavaScriptSerializer._serializeStringWithBuilder(object, stringBuilder);
27            }
28            
29            else if (Array.isInstanceOfType(object)) {
30              stringBuilder.append('[');
31              
32              for (i = 0; i < object.length; ++i) {
33                if (i > 0) {
34                  stringBuilder.append(',');
35                }
36                Sys.Serialization.JavaScriptSerializer._serializeWithBuilder(object[i], stringBuilder,false,prevObjects);
37              }
38              stringBuilder.append(']');
39            }
40            else {
41              if (Date.isInstanceOfType(object)) {
42                stringBuilder.append('"\\/Date(');
43                stringBuilder.append(object.getTime());
44                stringBuilder.append(')\\/"');
45                break;
46              }
47              var properties = [];
48              var propertyCount = 0;
49              for (var name in object) {
50                if (name.startsWith('$')) {
51                  continue;
52                }
53                if (name === Sys.Serialization.JavaScriptSerializer._serverTypeFieldName && propertyCount !== 0){
54                  properties[propertyCount++] = properties[0];
55                  properties[0] = name;
56                }
57                else{
58                  properties[propertyCount++] = name;
59                }
60              }
61              if (sort) properties.sort();
62              stringBuilder.append('{');
63                var needComma = false;
64                
65                for (i=0; i<propertyCount; i++) {
66                  var value = object[properties[i]];
67                  if (typeof value !== 'undefined' && typeof value !== 'function') {
68                    if (needComma) {
69                      stringBuilder.append(',');
70                    }
71                    else {
72                      needComma = true;
73                    }
74                    
75                    Sys.Serialization.JavaScriptSerializer._serializeWithBuilder(properties[i], stringBuilder, sort, prevObjects);
76                    stringBuilder.append(':');
77                    Sys.Serialization.JavaScriptSerializer._serializeWithBuilder(value, stringBuilder, sort, prevObjects);
78                    
79                  }
80                }
81                stringBuilder.append('}');
82            }
83          }
84          finally {
85            Array.removeAt(prevObjects, prevObjects.length - 1);
86          }
87        }
88        else {
89          stringBuilder.append('null');
90        }
91        break;
92      case 'number':
93        Sys.Serialization.JavaScriptSerializer._serializeNumberWithBuilder(object, stringBuilder);
94        break;
95      case 'string':
96        Sys.Serialization.JavaScriptSerializer._serializeStringWithBuilder(object, stringBuilder);
97        break;
98      case 'boolean':
99        Sys.Serialization.JavaScriptSerializer._serializeBooleanWithBuilder(object, stringBuilder);
100       break;
101     default:
102       stringBuilder.append('null');
103       break;
104     }
105   }
This is the JavaScript source for method _serializeWithBuilder(object, stringBuilder, sort, prevObjects) from ASP.NET AJAX Library. Full name for this method is Sys$Serialization$JavaScriptSerializer$_serializeWithBuilder(object, stringBuilder, sort, prevObjects). It belongs to the class JavaScriptSerializer, which is in Sys.Serialization namespace. This source is in MicrosoftAjax.debug.js file.
Bookmark and Share This
About  Contact  Privacy Policy  Site Map