var bar = 'bar';
var foobar = eval('"foo" + bar');
alert(foobar);
[/quote]
[list]
[*]evvar bar = 'bar';
// if variable bar equals 'bar', foobar is the result of
// last executing statement: bar="foo-bar";
var foobar = eval('if(bar == "bar") {bar="foo-bar";} else {bar = "bar-foo";}');
alert(foobar);// change the valuebar = 'foo';
// now our the last executed statement is: bar = "bar-foo";
// therefore the value of variable foobar has been changed
// into 'bar-foo'
foobar = eval('if(bar == "bar") {bar="foo-bar";} else {bar = "bar-foo";}');
alert(foobar);
[/quote]
[b]JSON的格式[/b]
JSON的格式是由大括号和由冒号(:)构成的名值对所组成的。注意JSON格式与对象字面量 (object literals) 的区别:JSON的名字部分严格用引号+名字来表示。
[b]举例说明[/b]
[list]
[*]对象的字面量 [/*][/list]
[quote]var objectLiteral = {
name: "Objector.L",
age: "24",
special: "JavaScript",
sayName: function() {
return this.name;
}
};
[/quote]
[list]
[*]JSON对象 [/*][/list]
[quote]var jsonFormat = {
"summary": "Blogs",
"blogrolls": [
{
"title": "Explore JavaScript",
"link": "http://example.com/"
},
{
"title": "Explore JavaScript",
"link": "http://example.com/"
}
]
};
[/quote]
[b]evvar jsonObject = eval("(" + jsonFormat + ")");
[/quote]
[b]为什么要加括号?[/b]
加上圆括号的目的是迫使evalert(eval("{}"); // return undefined
alert(eval("({})");// return object[Object]
[/quote]
[b]JSON格式的名字部分为什么要加引号?[/b]
因为evalert(eval('{foo:"bar"}')); // return "bar", incorrect
[/quote]
[list]
[*]evalert(eval('({"foo": "bar"})')); // return JSON object, correct
[/quote]
[b]结论[/b]
理解eveval('{' + jsonString + ')');
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有