的反序列化反序列化jsonString我得到錯誤錯誤。system.missingMethodException而:當JSON數組
錯誤是Type 'oodleListingsUser' is not supported for deserialization of an array.
我反序列化的代碼是
string jsonString = new WebClient().DownloadString("http://api.oodle.com/api/v2/listings?key=TEST®ion=region_value&category=category_value&format=json");
JavaScriptSerializer ser = new JavaScriptSerializer();
jsonOodleApi p = ser.Deserialize<jsonOodleApi>(jsonString);
我班jsonOodleApi的認定中是
public class jsonOodleApi
{
public oodleCurrent current;
public oodleListings[] listings;
public oodleMeta meta;
public string state { get; set; }
}
認定中oodleCurrent和oodleMeta我不會放棄,因爲這是完美的 !
的oodleListings認定中是
定義之public class oodleListings
{
public string id { get; set; }
public string title { get; set; }
public oodleListingsUser user;
// I have skipped some of fields because it have no issue at all.
}
oodleListingsUser是
public class oodleListingsUser
{
public string id { get; set; }
public string url { get; set; }
public string name { get; set; }
public string photo { get; set; }
}
問題是我的jsonString有時僅返回一個的用戶值(類型oodleListingsUser的),有時它會返回用戶數組和som etimes它返回用戶的空值!
當它返回只有一個用戶,它運行完全正常!沒有任何問題。
但是,當它返回的用戶陣列,綻放!發生錯誤Type 'oodleListingsUser' is not supported for deserialization of an array.
即使我已經試過public oodleListingsUser[] user
但它給錯誤的
No parameterless constructor defined for type of 'oodleListingsUser[]'
爲僅返回一個用戶的價值!
現在我該怎麼辦才能解決這個問題?
您是否嘗試過'public oodleListingsUser [] user;'? – 2012-02-07 09:37:36
@ L.B是的!它運行完美,如果jsonString返回用戶數組! 但如果jsonString返回一個用戶,它會給'類型的「oodleListingsUser []」'錯誤 – Chintan 2012-02-07 09:38:45
定義無參數的構造函數,甚至我有參數的構造函數在我的班級代碼!它仍然給錯誤! – Chintan 2012-02-07 09:40:23