JSON数据未使用getJSON显示 [英] JSON data not displayed using getJSON
本文介绍了JSON数据未使用getJSON显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
$('document').ready(function()
{
$.getJSON('news.php', parseInfo);
});
function parseInfo(data)
{
alert(data.news);//undefined
$('#info').html(data.news);
}
我的PHP输出(news.php)是[{"id":"20110428","news":"april 28 2011"}]
My PHP output(news.php) is [{"id":"20110428","news":"april 28 2011"}]
推荐答案
您的对象包装在数组中.
Your object is wrapped inside an array.
您需要data[0].news
或者从JSON输出中删除外部方括号.
Alternatively remove the outer square brackets from your JSON output.
这篇关于JSON数据未使用getJSON显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文