本文共 763 字,大约阅读时间需要 2 分钟。
下载json库自己找javascript的
或者直接去下面的
php生成json格式
使用页面
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());
}
转载地址:https://linuxstyle.blog.csdn.net/article/details/7178599 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!