2013-07-12 38 views
0

在Info.aspx.cs中,我從WebService獲取一個壓縮文件。解碼內容後,我有一個XML文件。使用XmlToJSONJavaScriptSerializer的結果是一個JSON對象。我如何在Info.aspx中使用此對象?如何使用在代碼後面創建的JSON對象?

+0

你怎麼想的ASPX的對象呢?在一些JavaScript中使用它?從道具上打印一些文字? – Graham

回答

0

假設你的JSON是如下ñ以下格式

var A={ 
    propertyOne: "propertyOne", 
    propertyTwo: "propertyTwo" 
} 

用途:

A.propertyOne 
A.propertyTwo 
+0

Info.aspx如何知道我在Info.aspx.cs中有'變量A' – Georg

+0

這只是一個例子。你可以用作你的 – Amit

0

試試這個,

var returnValue = new Object(); 
     returnValue.entityfirst = $("#entityfirst ").val(); 
     returnValue.entitysecond = $("#entitysecond ").val(); 
     returnValue.entitythird = $("#entitythird").val(); 

var request = $.ajax({ 
        url: ..., //access method url 
        type: 'POST', 
        cache: false, 
        data: JSON.stringify(returnValue), 
        dataType: 'json', 
        contentType: 'application/json; charset=utf-8' 
       }); 
0

在你的aspx頁面你有,如果你使用JavaScript做一個動態負載。

例如你打電話收到像這樣(jQuery的):

$.ajax({ 
       url: "myUrlPageForCallJsonService", 
        type: 'POST', 
        data: "yourParamsForGettingJson" 
        dataType: 'json', 
        complete: function (results) { console.log('complete'); }, 
        success: function (data) { //You logic in the success function 
         for (var i = 0; i < data.length; i++) { 
          console.log("success"); 
          _html += '<li>'+ data[i].Param1 + '</li>'; 
         } 

         _html += '</ul>'; 
         $('#renderbody').html(_html); 
        }, 
        fail: function (data) { console.log("fail"); } 
       }); 

希望這有助於

相關問題