简体   繁体   English

ExtJS无法解码JSON消息

[英]ExtJS cannot decode JSON message

I'm using ExtJS to make an Ajax request to server-side, and then I would like to parse the JSON response and do something with it. 我正在使用ExtJS向服务器端发出Ajax请求,然后我想解析JSON响应并对其执行某些操作。

The problem is the i can't decode the response text: 问题是我无法解码响应文本:

Ext.Ajax.request({
                                    url: 'Applications/GetFarmCounters.aspx',
                                    params: { farm: 'test', farmid: Ext.getCmp('farm_id').getValue() },
                                    success: function (result, request) {
                                        // result.responseText is here : {succes : true, message : 'test'}

                                        var jsonData = Ext.util.JSON.decode(result.responseText);

                                        Ext.MessageBox.alert('Success', 'Decode of stringData OK<br />jsonData.message= ' + jsonData.message);

                                    },
                                    failure: function (response, opts) {
                                        Ext.Msg.alert('Warning', 'Error!');
                                    }
                                });

But instead of seing the "test" message in an alert box, i get this error message in Chrome developer tools : "Uncaught SyntaxError: Unexpected token s" 但是,我没有在警告框中查看“测试”消息,而是在Chrome开发人员工具中收到此错误消息:“Uncaught SyntaxError:Unexpected token s”

What am i doing wrong? 我究竟做错了什么?

Thank you! 谢谢!

It's a JSON issue 这是一个JSON问题

{
    "success": true,
    "message": "test"
}

should be the JSON you return. 应该是你返回的JSON。 Always test your JSON using JSONLint 始终使用JSONLint测试您的JSON

Seems like this know issue. 好像这个知道问题。 Check here , if it solves your problem 检查一下 ,如果它解决了你的问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM