日期:2014-05-16 浏览次数:20479 次
[{'id':'1','message':'HEHE','sendtime':'2013-07-20 09:46:00'},{'id':'2','message':'大家好,这是测试数据......','sendtime':'2013-07-20 09:47:17'},{'id':'3','message':'我看啊 ,这个聊天工具很好用的啊','sendtime':'2013-07-20 09:47:46'},{'id':'13','message':'地对地导弹','sendtime':'2013-07-20 13:34:01'}]
var result=eval('('+data+')');
alert(result.toJSONString());
<script type="text/javascript">
var data=[{'id':'1','message':'HEHE','sendtime':'2013-07-20 09:46:00'},{'id':'2','message':'大家好,这是测试数据......','sendtime':'2013-07-20 09:47:17'},{'id':'3','message':'我看啊 ,这个聊天工具很好用的啊','sendtime':'2013-07-20 09:47:46'},{'id':'13','message':'地对地导弹','sendtime':'2013-07-20 13:34:01'}];
for(var d in data){
for( var j in data[d]){
alert(j+"="+data[d][j]);
}
}
</script>
function JsonToString(o) {
var arr = [];
var fmt = function(s) {
if (typeof s == 'object' && s != null) return JsonToString(s);
return /^(string
------解决方案--------------------
number)$/.test(typeof s) ? "'" + s + "'" : s;
}
for (var i in o)
arr.push("'" + i + "':" + fmt(o[i]));
return '{' + arr.join(',') + '}';
}
data = "[{'id':'1','message':'HEHE','sendtime':'2013-07-20 09:46:00'},{'id':'2','message':'大家好,这是测试数据......','sendtime':'2013-07-20 09:47:17'},{'id':'3','message':'我看啊 ,这个聊天工具很好用的啊','sendtime':'2013-07-20 09:47:46'},{'id':'13','message':'地对地导弹','sendtime':'2013-07-20 13:34:01'}]";