在我的應用程序中,我使用Web請求從Web源中提取json數據並將其反序列化到我的類中。然後我想從這些數據中提取特定的值,但是我發現我無法使用當前的代碼覆蓋。從類的價值是不可達的?
這裏是我的班
public class Result
{
public int id { get; set; }
public string name { get; set; }
public int trackNumber { get; set; }
public string title { get; set; }
public List<Artist> artists { get; set; }
public List<Genre> genres { get; set; }
public Release release { get; set; }
public Label label { get; set; }
public Images images { get; set; }
public int downloadId { get; set; }
public string downloadUrl { get; set; } // value i'm trying to retrieve
}
public class RootObject
{
public Metadata metadata { get; set; }
public ObservableCollection<Result> results { get; set; }
}
和反序列化,然後將數據試圖想要的值存儲到一個字符串變量
RootObject data = JsonConvert.DeserializeObject<RootObject>(response);
string downloadUrl = data.results.downloadUrl; // downloadUrl is unreachable
代碼是否有更好的方法來做到這一點得到我需要的價值?謝謝您的幫助。