JSON - способ записи Javascript.
Получение Json
1.Вручную
2.через сериализатор
Загрузка
var oRules
............
function load_Rules()
{
if (fso.FileExists("rules.js"))
{
var xf=fso.OpenTextFile("rules.js",1,true)
eval(xf.ReadAll())
xf.close()
} else
{
oRules =[]
}
}
1:
function Save_Rules()
{
var s
var f = fso.OpenTextFile("Rules.js", 2, true);
f.WriteLine("var oRules=[]")
for (var i=0;i<oRules.length;i++)
{
var Node=oRules[i]
s=["oRules[oRules.length]= {name:\""+ss(Node.name)+"\","]
s[s.length]="text:\""+ss(Node.text)+"\","
s[s.length]="list:["
var a=Node.list
for (j=0; j<a.length;j++)
{
s[s.length]="{fio:\""+a[j].fio+"\","
s[s.length]="e:"+a[j].e+"}"
if (j!=a.length-1)
s[s.length-1]+=","
}
s[s.length-1]+="]}\n\n"
f.WriteLine(s.join("\n"))
}
f.Close()
function ss(x)
{
return x.replace(/\\/g,"\\\\")
}
}
2:
function serialize(_obj,eol)
{
var xeol=(eol==null||!eol)?"":"\n "
// Other browsers must do it the hard way
switch (typeof _obj)
{
// numbers, booleans, and functions are trivial:
// just return the object itself since its default .toString()
// gives us exactly what we want
case 'number':
case 'boolean':
case 'function':
return _obj;
break;
// for JSON format, strings need to be wrapped in double-quotes
case 'string':
var a=['\\','\\\\','\n','\\n','\r','\\r',"'","\\'","\t","\\t"];
for(var i=0;i<8;i+=2){_obj=_obj.split(a[i]).join(a[i+1])};
_obj='\'' +_obj+ '\''
return _obj;
break;
case 'object':
var str;
if (_obj==null)
{
str="null"
}
else if (_obj.constructor === Array || typeof _obj.callee !== 'undefined')
{
var i, len = _obj.length;
if (len<1)
xeol=""
str = xeol+'[';
if (len)
for (i = 0; i < len; i++)
{ str += serialize(_obj[i],eol) + (i==len-1?"":','); }
str += ']'
}
else
{
str = xeol+'{';
var key;
var e=true
for (key in _obj) {
if (e)
e=!e
else
str+=xeol
str += key + ':' + serialize(_obj[key],eol) + ','; }
if (!e)
str = str.substr(0,str.length-(",").length)
str += '}'
}
return str;
break;
default:
return 'UNKNOWN';
break;
}
}
{
var f =fso.OpenTextFile("rules.js", 2, true)
f.Write("oRules="+serialize(oRules,true))
f.Close()
}