代码之家  ›  专栏  ›  技术社区  ›  Fazil

JSON响应处理

  •  0
  • Fazil  · 技术社区  · 12 年前

    这是我对“找不到记录”回复的JSON响应。当我试图检查“errorMsg”或“response”时,它不正常工作 JSON响应

    {
    "showItems" : 
       [
        {
         "errorMsg" : "NoRecordsFound",
         "response" : "failed"
        }
       ]
    }  
    

    状态检查

     success: function (response) 
     {
      var respObj = Ext.JSON.decode(response.responseText);
      alert(respObj[0].response);//here it does not retutning anyting
      if(respObj[0].response=="Success")
        {
          Ext.getCmp('itemList').setData(respObj.showItems);
        }
      if(respObj[0].response=="failed")
        {
          Ext.Msg.alert("Alert!","No records found!");
        }
     }
    

    如何检查情况?请帮我解决这个问题

    1 回复  |  直到 12 年前
        1
  •  1
  •   Viswa    12 年前
    Ext.JSON.decode(response.responseText) will return
    

    enter image description here

    您应该访问这样的响应

    respObj.showItems[0].response
    

    哪里

    respObj是对象

    showItems是数组

    响应&errorMsg是showItems数组中第一项的财产。

    尝试

    success: function (response) 
     {
      var respObj = Ext.JSON.decode(response.responseText);
      var response=  respObj.showItems[0].response;
      alert(response);
      if(response=="Success")
        {
          Ext.getCmp('itemList').setData(respObj.showItems);
        }
      if(response=="failed")
        {
          Ext.Msg.alert("Alert!","No records found!");
        }
     }