现在有点急,json解析问题~ <script language="JavaScript"><!-- var obj = {"ee:ee":"ttttt","111":"2222"} alert(obj["ee:ee"])//--></script> 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 如果 [ 等符号是在 串用出现,是没有影响的.不必要转义 ep:<script type="text/javascript" src="http://www.json.org/json.js"></script><script type="text/javascript">var a="test[554";b={"a":a};alert(b.toJSONString());</script> 只要你读取属性不用obj.属性 用obj.[属性] 读取键值 不会影响,{}会被解析为对象,[]会被解析为数组,另外你的这个语句有点问题,应该是{"eeee":"ttttt","111":"2222",date : [{"wwww":"4444"},{"wwww":"6666"}]},date后面掉了一个":" <script type="text/javascript">var JSON = function(sJSON){ this.objType = (typeof sJSON); this.self = []; (function(s,o){for(var i in o){o.hasOwnProperty(i)&&(s[i]=o[i],s.self[i]=o[i])};})(this,(this.objType=='string')?eval('0,'+sJSON):sJSON);}JSON.prototype = { toString:function(){ return this.getString(); }, valueOf:function(){ return this.getString(); }, getString:function(){ var sA = []; (function(o){ var oo = null; sA.push('{'); for(var i in o){ if(o.hasOwnProperty(i) && i!='prototype'){ oo = o[i]; if(oo instanceof Array){ sA.push(i+':['); for(var b in oo){ if(oo.hasOwnProperty(b) && b!='prototype'){ sA.push(oo[b]+','); if(typeof oo[b]=='object') arguments.callee(oo[b]); } } sA.push('],'); continue; }else{ sA.push(i+':'+oo+','); } if(typeof oo=='object') arguments.callee(oo); } } sA.push('},'); })(this.self); return sA.slice(0).join('').replace(/\[object object\],/ig,'').replace(/,\}/g,'}').replace(/,\]/g,']').slice(0,-1); }, push:function(sName,sValue){ this.self[sName] = sValue; this[sName] = sValue; }}var strA = '{eeee:"ttttt",111:"2222",date:[{"wwww":"4444"},{"wwww":"6666"}]}';var objA = new JSON(strA);alert(objA);alert(objA.eeee+'\n'+objA['111']+'\n'+objA.date);alert(objA.date[0].wwww+'\n'+objA.date[1].wwww);</script> 我找到问题所在了~~~我在value 里面加了1个\或3个\\\或5个\\\\\解析 就出了问题不知道有什么好的解析方法 replace成其他字符,之后再replace回来 哪位大哥能来分析下(百度联盟源码js)是否有判断鼠标点击还是程序点击?? 求教JS日期验证问题 json callback到底是咋回事?? pixelHeight为什么=0 我写的树形菜单为有一个漏洞帮忙看一下 请问怎样使网页隔一段时间后自动post一次? 窗口问题? 请问层能不能设为不透明的? 后台接收前台Ajax所传的值 jsp怎么拿单选按钮的值填充到当前页面上 这个联动问题怎么解决啊,大侠们救救我啊 晕了,NS_ERROR_DOM_INDEX_SIZE_ERR什么意思?
<script type="text/javascript" src="http://www.json.org/json.js"></script><script type="text/javascript">
var a="test[554";
b={"a":a};alert(b.toJSONString());</script>
this.objType = (typeof sJSON);
this.self = [];
(function(s,o){for(var i in o){o.hasOwnProperty(i)&&(s[i]=o[i],s.self[i]=o[i])};})(this,(this.objType=='string')?eval('0,'+sJSON):sJSON);
}
JSON.prototype = {
toString:function(){
return this.getString();
},
valueOf:function(){
return this.getString();
},
getString:function(){
var sA = [];
(function(o){
var oo = null;
sA.push('{');
for(var i in o){
if(o.hasOwnProperty(i) && i!='prototype'){
oo = o[i];
if(oo instanceof Array){
sA.push(i+':[');
for(var b in oo){
if(oo.hasOwnProperty(b) && b!='prototype'){
sA.push(oo[b]+',');
if(typeof oo[b]=='object') arguments.callee(oo[b]);
}
}
sA.push('],');
continue;
}else{
sA.push(i+':'+oo+',');
}
if(typeof oo=='object') arguments.callee(oo);
}
}
sA.push('},');
})(this.self);
return sA.slice(0).join('').replace(/\[object object\],/ig,'').replace(/,\}/g,'}').replace(/,\]/g,']').slice(0,-1);
},
push:function(sName,sValue){
this.self[sName] = sValue;
this[sName] = sValue;
}
}var strA = '{eeee:"ttttt",111:"2222",date:[{"wwww":"4444"},{"wwww":"6666"}]}';
var objA = new JSON(strA);
alert(objA);
alert(objA.eeee+'\n'+objA['111']+'\n'+objA.date);
alert(objA.date[0].wwww+'\n'+objA.date[1].wwww);
</script>
解析 就出了问题
不知道有什么好的解析方法