我从http://itunes.apple.com/lookup?id=796171602
这个链接总是给我一个只有一个项目的数组。因此,我不想使用根对象和结果数组创建一个类,而是要获取唯一的第一个对象并直接使用。
WebClient webClient = new WebClient();
webClient.Encoding = Encoding.UTF8;
string appJsonData = webClient.DownloadString("http://itunes.apple.com/lookup?id=796171602");
App app = new App();
JToken rootObject = JToken.Parse(appJsonData);
JToken appToken = rootObject["results"];
app = JsonConvert.DeserializeObject<App>(appJsonData);
反序列化时,我得到:
The input is not a valid Base-64 string as it contains a non-base 64 character, more than two padding characters, or an illegal character among the padding characters.
当我使用 jsonpack.com 创建 ac# 类时,它可以工作。
我的自定义对象是这样的:
public class App : Entity
{
//it's not app id in the data base
[JsonProperty("trackId")]
public virtual int AppStoreId { get; set; }
[JsonProperty("trackViewUrl")]
public virtual string AppStoreLink { get; set; }
[JsonProperty("sellerName")]
public virtual string SellerName { get; set; }
[JsonProperty("artworkUrl60")]
public virtual string Icon { get; set; }
[JsonProperty("trackName")]
public virtual string Name { get; set; }
[JsonProperty("formattedPrice")]
public virtual string FormattedPrice { get; set; }
[JsonProperty("primaryGenreName")]
public virtual string Genre { get; set; }
[JsonProperty("Description")]
public virtual string Description { get; set; }
[JsonProperty("releaseNotes")]
public virtual string ReleaseNotes { get; set; }
[JsonProperty("releaseDate")]
public virtual DateTime ReleaseDate { get; set; }
[JsonProperty("userRatingCountForCurrentVersion")]
public virtual string UserRatingCountForCurrentVersion { get; set; }
[JsonProperty("averageUserRatingForCurrentVersion")]
public virtual string AverageUserRatingForCurrentVersion { get; set; }
[JsonProperty("fileSizeBytes")]
public virtual string FileSize { get; set; }
[JsonProperty("screenshotUrls")]
public virtual IList<string> IPhoneSceenShots { get; set; }
[JsonProperty("ipadscreenshotUrls")]
public virtual IList<string> IPadSceenShots { get; set; }
public App()
{
IPhoneSceenShots = new List<string>();
IPadSceenShots = new List<string>();
}
}
昨晚还好好的,今天就不行了。有人知道吗?