无法访问阿贾克斯JSON数据对象 [英] Cannot access Ajax JSON data objects

查看:115
本文介绍了无法访问阿贾克斯JSON数据对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Ajax调用JSON响应返回,但似乎无法访问任何部分的JSON在所有。

JSON格式是: [{ID:1,说明:员工,覆盖:中心,覆盖:X}]

我已经尝试了以下内容并没有什么作品:

 成功:函数(结果,要求){
    jsonData = Ext.util.JSON.de code(result.responseText);
    VAR ID = jsonData.id;
    警报(ID);
 }

 *收益为未定义

成功:函数(结果,要求){
    jsonData = result.responseText ##显示了JSON的完美
    警报(jsonData.length)###显示为数字字符的,在JSON字符串没有多少对象
}
 

解决方案

Ext.util.JSON.de code 是ExtJS3方法和 Ext.JSON.de code 在ExtJS4,因为你没有指明哪个ExtJS的版本使用的是这样的故障安全方式将是使用 Ext.de $ C $ç这两个ExtJS3和ExtJS4可

 成功:函数(结果,要求){
    jsonData = Ext.de code(result.responseText);
    执行console.log(jsonData);
}
 

I have a JSON response returning from an Ajax call but cannot seem to access any part of the JSON at all.

The JSON format is: [{"id":"1","description":"Employee","coverage":"Center","covered":"X"}]

I have tried the following and nothing works:

success: function(result, request){
    jsonData = Ext.util.JSON.decode(result.responseText);
    var id = jsonData.id;
    alert(id);
 }

 * returns as undefined

success: function(result,request){
    jsonData = result.responseText  ##shows the Json perfectly
    alert(jsonData.length) ### displays as number of chars, not how many objects in json string
}

解决方案

Ext.util.JSON.decode is ExtJS3 method and Ext.JSON.decode is in ExtJS4, as you have not indicated which version of ExtJS you are using so failsafe way will be to use Ext.decode which is available in both ExtJS3 and ExtJS4

success: function(result, request){
    jsonData = Ext.decode(result.responseText);
    console.log(jsonData);
}

这篇关于无法访问阿贾克斯JSON数据对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆