wordpress ブログから画像を取得したいと考えています。すべての投稿画像ではなく、1 つの投稿だけから始めます。
私はこのコードを使用しています。タイトル、抜粋、URLを取得するために機能します...しかし、画像を取得できません:
名前空間WpWordpressJson {
public class MainViewModel : INotifyPropertyChanged
{
public MainViewModel()
{
this.Items = new ObservableCollection<ItemViewModel>();
}
/// <summary>
/// A collection for ItemViewModel objects.
/// </summary>
public ObservableCollection<ItemViewModel> Items { get; private set; }
private string _sampleProperty = "Sample Runtime Property Value";
/// <summary>
/// Sample ViewModel property; this property is used in the view to display its value using a Binding
/// </summary>
/// <returns></returns>
public string SampleProperty
{
get
{
return _sampleProperty;
}
set
{
if (value != _sampleProperty)
{
_sampleProperty = value;
NotifyPropertyChanged("SampleProperty");
}
}
}
public bool IsDataLoaded
{
get;
private set;
}
/// <summary>
/// Creates and adds a few ItemViewModel objects into the Items collection.
/// </summary>
public void LoadData()
{
WebRequest.RegisterPrefix("http://automaticband.es/bio/", WebRequestCreator.ClientHttp);
Uri serviceUri = new Uri("http://automaticband.es/bio/?json=get_recent_posts");
WebClient downloader = new WebClient();
downloader.OpenReadCompleted += new OpenReadCompletedEventHandler(downloader_OpenReadCompleted);
downloader.OpenReadAsync(serviceUri);
}
public event PropertyChangedEventHandler PropertyChanged;
private void NotifyPropertyChanged(String propertyName)
{
PropertyChangedEventHandler handler = PropertyChanged;
if (null != handler)
{
handler(this, new PropertyChangedEventArgs(propertyName));
}
}
void downloader_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
{
if (e.Error == null)
{
try
{
Stream responseStream = e.Result;
DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(Posts));
Posts response = (Posts)ser.ReadObject(responseStream);
if (response.posts != null && response.posts.Count > 0)
{
foreach (Post post in response.posts)
{
this.Items.Add(new ItemViewModel() { LineOne = post.title, LineTwo = post.excerpt });
}
}
}
catch (Exception x)
{
return;
}
this.IsDataLoaded = true;
}
}
}
[DataContract]
public class Post
{
[DataMember]
public int id;
[DataMember]
public string type;
[DataMember]
public string slug;
[DataMember]
public string title;
[DataMember]
public string content;
[DataMember]
public string excerpt;
}
[DataContract]
public class Posts
{
[DataMember]
public int count;
[DataMember]
public int count_total;
[DataMember]
public List<Post> posts;
}
このサイトから入手しました:
http://kevinashley.com/connect-windows-phone-7-apps-to-wordpress-using-json/
すべてをありがとう