Ext.JSON.decode():您正在尝试解码无效的JSON字符串 [英] Ext.JSON.decode(): You're trying to decode an invalid JSON String

查看:565
本文介绍了Ext.JSON.decode():您正在尝试解码无效的JSON字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这方面还很陌生,自2个星期以来一直在尝试解决我的问题,希望能对您有所帮助.

I'm pretty new at this and have been trying to fix my problem since 2 weeks now hope you can help.

似乎我的json输出无效,但是我不确定我的问题是否来自我的php或extjs脚本.

It seems my json output is not valid but I'm not sure if my problem is coming from my php or my extjs script.

我有一个组合框,当我单击它时,应该显示给我一个选择列表. 该列表基本上来自Sql表.

I have a combo box wich should show me a list of choice when I click on it. The list is basically comming from a Sql table.

当我在Chrome浏览器中检入控制台时,我会看到输出,一切正常.

When I check in my console in Chrome I see my output and it seems fine.

ext-all-rtl-debug.js?_dc=1525825768241:10025 [E] Ext.JSON.decode(): You're trying to decode an invalid JSON String: Connection to DB succeed    
        [{"id":"3","businessunit":"kappa"}] 

我应该看到kappa并能够选择它,但除了json错误,我什么也没有.

I should see kappa and be able to select it but I have nothing just the json error.

这是我的php:

    <?php
    require_once"..//..//_includes/headers.php";


$query = "select id, businessunit from Team_tab order by businessunit";
logit($query);
$result = odbc_exec($connection,$query);
while($row = odbc_fetch_array($result))
    {
    $myArray[] = array(
        'id'=>$row['id'],
        'businessunit'=>$row['businessunit'],
        );


    }

    if (isset($myArray))
    {
        if ( sizeof($myArray) > 0 )
        {
            $output = json_encode($myArray);
            echo $output;
        }
        else
        {
            echo '(success:true,"error":0)';    
        }
    }
    else
        {
            echo '(success:true,"error":0)';
        }

    ?>

这是我的extjs:

Ext.define('EmpMen.view.Employee.CreateEmployee', {
        extend: 'Ext.window.Window',
        alias: 'widget.employee.createemployee',

    requires: [
        'EmpMen.view.Employee.CreateEmployeeViewModel',
        'EmpMen.view.Employee.CreateEmployeeViewController',
        'Ext.form.Panel',
        'Ext.form.field.ComboBox',
        'Ext.button.Button'
    ],

    controller: 'employee.createemployee',
    viewModel: {
        type: 'employee.createemployee'
    },
    reference: '',
    height: 325,
    itemId: 'createEmployee',
    width: 364,
    title: 'Enter Employee Information',

    layout: {
        type: 'vbox',
        align: 'stretch'
    },
    items: [
        {
            xtype: 'form',
            flex: 1,
            height: 170,
            padding: 10,
            width: 360,
            bodyPadding: 10,
            title: '',
            items: [
                {
                    xtype: 'textfield',
                    anchor: '100%',
                    reference: 'first',
                    itemId: 'first',
                    fieldLabel: 'First Name'
                },
                {
                    xtype: 'textfield',
                    anchor: '100%',
                    reference: 'last',
                    itemId: 'last',
                    fieldLabel: 'Last Name'
                },
                {
                    xtype: 'textfield',
                    anchor: '100%',
                    reference: 'tle',
                    itemId: 'tle',
                    fieldLabel: 'Title'
                },
                {
                    xtype: 'combobox',
                    anchor: '100%',
                    reference: 'bunit',
                    fieldLabel: 'Business Unit',
                    displayField: 'businessunit',
                    valueField: 'id',
                    bind: {
                        store: '{businessunit}'
                    }
                },
                {
                    xtype: 'textfield',
                    anchor: '100%',
                    reference: 'exp',
                    itemId: 'exp',
                    fieldLabel: 'Experience'
                },
                {
                    xtype: 'container',
                    margin: 10,
                    layout: {
                        type: 'hbox',
                        align: 'stretch',
                        pack: 'center'
                    },
                    items: [
                        {
                            xtype: 'button',
                            flex: 1,
                            reference: 'employeeForm',
                            maxWidth: 100,
                            width: '',
                            text: 'Save',
                            listeners: {
                                click: 'onButtonClick'
                            }
                        }
                    ]
                }
            ]
        }
    ],
    listeners: {
        afterrender: 'onCreateEmployeeAfterRender'
    }

});

推荐答案

来源: 根据发生错误的 Ext.JSON.decode 方法的来源,PHP的响应应为:

According to the Ext.JSON.decode method's source where the error is occurring, the response from PHP should be following :

Connection to DB succeed    
    [{"id":"3","businessunit":"kappa"}]

这不是有效的JSON响应.应该是:

This is not a valid JSON response. It should be :

[{"id":"3","businessunit":"kappa"}]

根据提供的来源,我怀疑应该从连接到数据库成功"附加字符串出现的唯一位置是:

According to the source provided, I suspect the only place from where "Connection to DB succeed" additional string should be coming is :

require_once"..//..//_includes/headers.php";

从headers.php中删除echo语句与数据库的连接成功".

这篇关于Ext.JSON.decode():您正在尝试解码无效的JSON字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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