如何从$ .parseJSON(数据)获取数据

时间:2016-12-08 06:48:12

标签: javascript jquery

我正在尝试通过ajax获取数据,在调用$.parseJSON(data)之前代码工作正常,但在调用$.parseJSON(data)时显示空对象。这是我的代码。

success: function(data){
        //alert(data);//working fine here
        var result = $.parseJSON(data);
        alert(result); //issue is here. }

enter image description here

console.log(result);的输出是:

[{"pkjobid":"13","fkuserid":"42","companyname":"Testing Company","jobtitle":"Testing Vr","startdate":"Mar 2016","enddate":"Dec 2016","jobdescription":"verime testing","jobstatus":"1","created_date":"2016-12-07","update‌​d_date":null}]

2 个答案:

答案 0 :(得分:0)

它不是一个空响应,它包含一个对象,你无法正确看到它,因为它的toString()方法不可用。

Try console.log(result) and open the console to check out the result

答案 1 :(得分:0)

对于您的上下文使用JSON.parse(result);

您使用的是jquery 3.1.1版。从jQuery 3.0开始,不推荐使用$ .parseJSON。要解析JSON字符串,请使用本机JSON.parse方法。

相关问题