<p>我试图访问从python脚本发送的json数据。在python脚本中,我以以下格式向Ajax成功函数发送数据:</p>
<pre><code>def main():
"""Create instance of FieldStorage"""
dat = cgi.FieldStorage( keep_blank_values = True )
Start_date = "07/01/2013"
dc = ['las','sjc']
sys = "All"
result = [{"startdate":Start_date,"datacenter":dc,"system":sys}]
res = json.dumps(result)
print res
</code></pre>
<p>现在在javascript中,我试图访问Json的各个值,但是在console.log中收到一条消息,上面写着“undefined”。但是数据打印正确,我无法访问JSON的各个对象。</p>
<pre><code> $.ajax({
type: 'get',
url: '/cgi-bin/worlddata.py',
data: $(form).serialize(),
success: function(data, status) {
var response = JSON.parse(data);
console.log("THe json is "+response.datacenter); //prints undefined
console.log("result is "+data); // prints result is [{"startdate": "07/01/2013", "system": "All", "datacenter": ["las", "sjc"]}]
console.log("The status is "+status); // prints The status is success
console.log(data.datacenter); // prints undefined
</code></pre>
<p>我的问题是如何访问response.message或data.message?有人能指出我做错了什么吗?</p>