2013-09-21 38 views
0

喜的我初學者在asp.net我在aspx頁面下面的JSON:訪問JSON在JavaScript文件

{ 
    { 
     "Status":"<%= this._result.ToString().ToLower() %>" , 
     "SavePath":"<%= this.FileUrl%>" , 
     "FileName":"<%= this.Request["qqfile"] %>", 
     "SizeError":"<%= this._sizeError.ToString().ToLower()%>", 
     "ImgValidation":"<%=this._Imgvalid.ToString().ToLower()%>" 

    } 
    } 

我需要使用像打擊JS文件中的JSON:

if (responseJSON.Status == 'false') { 


       $.pushMessage({ 
        message: 'خطا در بارگزاری اطلاعات!', 
        messageClass: 'loader-message', 
        delay: 3500 
       }); 
       return; 
      } 

      else { 

       $(options.imgPath).attr("value", responseJSON.SavePath); 


       $(options.imgName).html(responseJSON.FileName); 
      } 

我如何使用JSON坦克

+0

你是什麼意思「使用json」?你已經在使用它,當你做responseJSON.Status – Meistro

+0

在js它不工作 – HamidSadeghi

+0

你的JSON無效開始。你的括號嵌套太深了。您無法引用「狀態」,因爲您無法引用持有「狀態」的對象。 – Meistro

回答

0

簡而言之,您的JSON無效。你有

{ 
{ 
    "Status":"<%= this._result.ToString().ToLower() %>" , 
    "SavePath":"<%= this.FileUrl%>" , 
    "FileName":"<%= this.Request["qqfile"] %>", 
    "SizeError":"<%= this._sizeError.ToString().ToLower()%>", 
    "ImgValidation":"<%=this._Imgvalid.ToString().ToLower()%>" 

} 
} 

,但它應該是

{ 
    "Status":"<%= this._result.ToString().ToLower() %>" , 
    "SavePath":"<%= this.FileUrl%>" , 
    "FileName":"<%= this.Request["qqfile"] %>", 
    "SizeError":"<%= this._sizeError.ToString().ToLower()%>", 
    "ImgValidation":"<%=this._Imgvalid.ToString().ToLower()%>" 

} 

然後,你可以參考屬性responseJSON.Status,responseJSON.SavePath等 JSON對象就是這樣 - 一個對象。如果那個對象沒有名字,你怎麼可以參考它?什麼是有效的是

{ 
    JSONResponse:{ 
    "Status":"<%= this._result.ToString().ToLower() %>" , 
    "SavePath":"<%= this.FileUrl%>" , 
    "FileName":"<%= this.Request["qqfile"] %>", 
    "SizeError":"<%= this._sizeError.ToString().ToLower()%>", 
    "ImgValidation":"<%=this._Imgvalid.ToString().ToLower()%>" 

    } 
}