2012-03-16 103 views
0

我試圖反序列化這個JSON:反序列化,JSON,WP7

[ 
    { 
     "Address": "String content", 
     "CategoryId": 2147483647, 
     "CategoryName": "String content", 
     "City": "String content", 
     "Email": "String content", 
     "GroupComment": "String content", 
     "GroupName": "String content", 
     "IntegrationType": "String content", 
     "Location": { 
      "Latitude": 1267432330000000, 
      "Longitude": 1267432330000000 
     }, 
     "Phone": "String content", 
     "StoreComment": "String content", 
     "StoreName": "String content", 
     "Website": "String content", 
     "ZipCode": "String content" 
    } 
] 
    ....... 

我有2類:

public class Stores 
    { 
     public string Address { get; set; } 
     ....... 
     public GeoLocation geoLocation { get; set; } 
    } 

    public class GeoLocation 
    { 
     public double Latitude { get; set; } 
     public double Longitude { get; set; } 
    } 

而且我反序列化JSON的是這樣的:

Stores[] st = new Stores[200]; 
MemoryStream ms = new MemoryStream(Encoding.Unicode.GetBytes(e.Result)); 
DataContractJsonSerializer serializer = new DataContractJsonSerializer(st.GetType()); 
st = serializer.ReadObject(ms) as Stores[]; 
ms.Close(); 

我得到地址等,但地理位置「無法評估表達式」。

出了什麼問題?

彼得

+0

第一個問題:這不是JSON,它是XML。 – 2012-03-16 08:40:13

+0

對不起。粘貼XML版本-Ouups。現在問題是正確的JSON。 – 2012-03-16 08:46:52

回答

1

嘗試將geoLocation成員名更改爲位置?

+0

我改變了類:public class Stores { public string Address {get;組; } public Location Location {get;組; } } public class Location { public string Latitude {get;組; } public string Longitude {get;組; } }謝謝! – 2012-03-16 10:23:24