前端获取后台返回的JSON数组对象数据后,取值的时候为undefind

var AddEchartsData = function () {

    var Url = _url + "sys/coupler/getEchartsCouplerNative";    

    $.ajax({

        type: "GET",

        url: Url,

        dataType: "json",

        contentType: "application/x-www-form-urlencoded;charset=UTF-8",

        success: (json)=>{

            alert(json);

            alert(JSON.stringify(json));

            

            //存在问题:打印json格式为[object,object],共51条数组;但打印JSON.stringify(json),

            //数据变为30条,且第30条信息显示不全

                xAxisData = [];//x轴数据

                BaseINData = [];

                BaseOUTData = [];

                FurnaceINData = [];

                FurnaceOUTData = [];

                ZROWData = [];     

            if(json!=null&&json.length>0){                                                                                                                                                                                                                                                                             

                for (var i=0;i<json.length;i++) 

                {

                    //alert(json[i])

                    if(json[i]!=""||json[i]!==undefined||json[i]!==null){

                    xAxisData.push(json[i].coupeZero.trim());

                    BaseINData.push(json[i].baseIN);

                    BaseOUTData.push(json[i].baseOUT);

                    FurnaceINData.push(json[i].FurnaceIN);

                    FurnaceOUTData.push(json[i].FurnaceOUT);

                    ZROWData.push(json[i].row);}

                

                }

            }

 

                alert(FurnaceINData);

                alert(FurnaceOUTData);

                alert(xAxisData);

                alert(BaseINData);

                alert(BaseOUTData);

                alert(ZROWData);

                                

                myChart.setOption({

                      series: [

                        {

                            name: '内侧底板温度',

                            data: BaseINData

                        },

                        {

                            name: '外侧底板温度',

                            data: BaseOUTData

                        },

                        {

                            name: '炉内内侧温度',

                            data: FurnaceINData

                        },

                        {

                            name: '炉内外侧温度',

                            data: FurnaceOUTData

                        },

                        {

                            name: '对应ROW号',

                            data: ZROWData

                        }

                        ],

                        title: {

                            text: 'SRAF1热电偶实时监控',

                            x:'center',

                            y:'5px',

                            left:'center'

                        },

                      xAxis: [

                        {

                             data: xAxisData

                        }

                        ]

                });

 },

        error: function (error) {

            toast("调用出错" + error.responseText);

        }

    });   

};

alert(json);时,显示[object,object]

alert(xAxisData);alert(BaseINData);alert(BaseOUTData);alert(ZROWData);这4个有值,赋值成功了

alert(FurnaceINData);alert(FurnaceOUTData)这2个显示undefined,什么原因呢?

 

查看全部
zhangruiCSDN
zhangruiCSDN
2020/11/27 16:33
  • html5
  • json
  • ajax
  • javascript
  • 点赞
  • 收藏
  • 回答
    私信

3个回复