]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - include/JSON.js
Release 6.1.4
[Github/sugarcrm.git] / include / JSON.js
1 /*
2  Copyright (c) 2005 JSON.org
3  
4  Permission is hereby granted, free of charge, to any person obtaining a copy
5  of this software and associated documentation files (the "Software"), to deal
6  in the Software without restriction, including without limitation the rights
7  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8  copies of the Software, and to permit persons to whom the Software is
9  furnished to do so, subject to the following conditions:
10  
11  The Software shall be used for Good, not Evil.
12  
13  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19  SOFTWARE.
20  
21  json.js
22  
23  The global object JSON contains two methods.
24  
25  JSON.stringify(value) takes a JavaScript value and produces a JSON text.
26  The value must not be cyclical.
27  
28  JSON.parse(text) takes a JSON text and produces a JavaScript value. It will
29  return false if there is an error.
30  
31  2008-10-10: New regular expressions copied in from the new json2.js file on http://json.org (released into the public domain), work better on Safari and IE for more complicated datasets
32  */
33 var JSON=function(){var m={'\b':'\\b','\t':'\\t','\n':'\\n','\f':'\\f','\r':'\\r','"':'\\"','\\':'\\\\'},s={array:function(x){var a=['['],b,f,i,l=x.length,v;for(i=0;i<l;i+=1){v=x[i];f=s[typeof v];if(f){v=f(v);if(typeof v=='string'){if(b){a[a.length]=',';}
34 a[a.length]=v;b=true;}}}
35 a[a.length]=']';return a.join('');},'boolean':function(x){return String(x);},'null':function(x){return"null";},number:function(x){return isFinite(x)?String(x):'null';},object:function(x){if(x){if(x instanceof Array){return s.array(x);}
36 var a=['{'],b,f,i,v;for(i in x){if(!x.hasOwnProperty||x.hasOwnProperty(i)){v=x[i];f=s[typeof v];if(f){v=f(v);if(typeof v=='string'){if(b){a[a.length]=',';}
37 a.push(s.string(i),':',v);b=true;}}}}
38 a[a.length]='}';return a.join('');}
39 return'null';},string:function(x){var unicode=new String;for(var i=0;i<x.length;i++){var temp=x.charCodeAt(i).toString(16);while(temp.length<4){temp="0"+temp;}
40 unicode+='\\u'+temp;}
41 return'"'+unicode+'"';}};return{stringify:function(v){var f=s[typeof v];if(f){v=f(v);if(typeof v==='string'){var securityEnvelope="{asynchronous_key:'"+asynchronous_key+"', jsonObject:"+v+"}";return securityEnvelope;}}
42 return;},destringify:function(str){},stringifyNoSecurity:function(v){var f=s[typeof v];if(f){v=f(v);if(typeof v==='string'){return v;}}
43 return;},destringify:function(str){},parse:function(text){text=text.replace(/^\s*|\s*$/,'');if(text.substr){if(text.substr(0,11)=="while(1);/*"){text=text.substr(11);text=text.substr(0,(text.length-2));}}
44 try{if(/^[\],:{}\s]*$/.test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g,'@').replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,']').replace(/(?:^|:|,)(?:\s*\[)+/g,''))){return eval('('+text+')');}else{return false;}}catch(e){return false;}},parseNoSecurity:function(text){try{if(/^[\],:{}\s]*$/.test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g,'@').replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,']').replace(/(?:^|:|,)(?:\s*\[)+/g,''))){return eval('('+text+')');}else{return false;}}catch(e){return false;}}};}();