2011-10-03 84 views
0
var a = JSON.Deserialize<object>(e.ExtraParams["address"]); 

的JSONASP.NET - JSON鑄造

[{"id":"","country":"MYcOUNTRY","city":"citycitycity","street":"street","block":"house","building":"building","additionalInfo":"fdsfdsfdsfds","latitude":"32.9206000","longitude":"35.1003000"}] 

以及用於存儲有關地址

[Serializable] 
class BEAddress{ 
    public string Id { get; set; } 
    public string Country { get; set; } 
    public string City { get; set; } 
    public string Street { get; set; } 
    public string Block { get; set; } 
    public string Building { get; set; } 

    public string Latitude { get; set; } 
    public string Longitude { get; set; } 
    public string AdditionalInfo { get; set; } 
    } 

我不能精明怎麼投對象aBEAddress信息類?

UPDATE: 的方式我seriliaze這個數據

<script type="text/javascript"> 
      var <%=ClientID%>_getAddress = function() { 
       var jsonObj = []; 
       jsonObj.push({ 
         Id: <%=AddressIdHdn.ClientID%>.getValue(), 
         Country: <%=cmbCountries.ClientID%> .getRawValue(), 
         City: <%=cmbCities.ClientID%> .getRawValue(), 
         Street: <%=txtStreet.ClientID%> .getValue(), 
         Block: <%=txtBlock.ClientID%> .getValue(), 
         Building: <%=txtBuilding.ClientID%> .getValue(), 
         AdditionalInfo: <%=txtAdditionalInfo.ClientID%> .getValue(), 
         Latitude: <%=txtLatitude.ClientID%> .getValue(), 
         Longitude: <%=txtLongitude.ClientID%> .getValue() 
        }); 
       return jsonObj; 
      } 
</script> 

回答

1

我可以想象你需要做到以下幾點:

BEAddress aVar = JSON.Deserialize<BEAddress>(e.ExtraParams["address"]); 

此刻你把你的JSON成爲一個bog標準的'對象',所以你需要把JSON變成一個特定的'BEAddress'對象,如上例所示。

+0

時發生的錯誤「不能反序列化JSON數組類型‘Loginet.Entities.BEAddress’」。 – Alexandre

+0

唯一突出的是你的類擁有用大寫字母定義的屬性,而你的JSON全部是小寫字母。看看我是如何做到這一點的,然後才需要比賽。出於興趣,這是與Ext.NET? – dougajmcdonald

+0

是的,它是ext.net。錯誤是一樣的。 json的結果是:[{「id」:「」,「country」:「Израиль」,「city」:「Гэдера」,「street」:「street」,「block」:「house」,「building」: 「building」,「additionalInfo」:「fdsfdsfdsfds」,「緯度」:「32.9206000」,「經度」:「35.1003000」}]' – Alexandre

0

如果您嘗試以下會發生什麼:

var a = JSON.Deserialize<BEAddress>(e.ExtraParams["address"]); 

你當前做的是反序列化到一個通用的object,而你需要一個BEAddress

另外放置[Serializable]屬性到BEAddress