This class also extends the native JSON interface with functions to support date encoding and parsing both in browser standard ISO format (default) and Microsoft's custom date encoding format.
This class is not loaded if a browser that natively supports JSON is used as most modern browsers do. The interface to this JSON class matches native JSON classes.It is based on Douglas Crockford's JSON JavaScript code with a number of modifications to handle date formatting in ISO and Microsoft formats. The parse() method checks for invalid characters in the JSON string before parsing and disallows executable code.
var person = { Name: "Rick", Company: "West Wind", Entered: new Date() }; var json = JSON.stringify(person); //{"Name":"Rick","Company":"West Wind","Entered":""2009-01-03T18:10:00Z""} alert(json); var copied = JSON.parseWithDates(json); alert( copied.Entered + " - " + copied.Name);
Dates are formatted in ISO date format by default. You can use stringifyWcf() to force dates to be encoded in Microsoft's date format. You can use the .parseWithDate() function to retrieve date values as real dates.
Member | Description | |
---|---|---|
dateStringToDate | Converts an ISO or MS AJAX style date into a date object. o.JSON.dateStringToDate(dateString)
|
|
parse | Parses a JSON string into a JavaScript value or object. This version throws an exception if parsing fails. o.JSON.parse(text)
|
|
parseWithDate | Parses a JSON string into a value or object. o.JSON.parseSafe(json)
|
|
stringify | Serializes a JavaScript object into a JSON string. o.JSON.stringify(object)
|
|
stringifyWcf | A Wcf specific version of stringify that properly encodes dates for WCF style formatting ("/Date(9312333123)/"). o.JSON.stringifyWcf(val)
|