http://www.json.org/json-zh.html自己找javascript的
或者直接去下面的
https://github.com/douglascrockford/JSON-js
php生成json格式
使用页面
<script src="scripts/json.js"></script>
alert(data.toJSONString());
如果返回false说明没数据
functionshowJSON() {
varuser =
{
"username":"tom",
"age":20,
"info": {"tel":"123456","cellphone":"98765"},
"address":
[
{"city":"shanghai","postcode":"201203"},
{"city":"suzhou","postcode":"200000"}
]
}
alert(user.username);
alert(user.age);
alert(user.info.cellphone);
alert(user.address[0].city);
alert(user.address[0].postcode);
}
修改
user.username ="jerry";
可以使用eval来转换JSON字符到Object
functionmyEval() {
varstr = '{"name":"Violet","occupation":"character"}';
varbj = eval('(' + str + ')');
alert(obj.toJSONString());
}
或者使用parseJSON()方法
functionmyEval() {
varstr = '{"name":"Violet","occupation":"character"}';
varbj = str.parseJSON();
alert(obj.toJSONString());
}
本文介绍如何使用JavaScript操作JSON数据,包括生成JSON格式的数据、通过eval或parseJSON方法将JSON字符串转换为对象,以及如何访问这些数据。
1759

被折叠的 条评论
为什么被折叠?



