0

I convert collection to JSON string.

ReadOnlyCollection<Post> wall = api.Wall.Get(-group.Id.Value, out totalCount, count);
string json = JsonConvert.SerializeObject(wall, Formatting.Indented);

get string json like this

 [
  {
    "Id": 144159,
    "Text": "Если",
    "Likes": {
      "Count": 9307,
      "UserLikes": false,
      "CanLike": true,
      "CanPublish": true
    },
    "PostType": "post",
    "PostSource": {
      "Type": "api",
      "Data": null
    },
    "Attachments": [
      {
        "Instance": {
          "AlbumId": -7,
          "Photo75": "http://cs629506.vk.me/v629506780/3a56/Sn3eI5qEtc0.jpg",
          "Photo130": "http://cs629506.vk.me/v629506780/3a57/tKRNTJlSH1s.jpg",
          "Photo604": "http://cs629506.vk.me/v629506780/3a58/wyz6H7Py_8U.jpg",
        },
        "Type": "VkNet.Model.Attachments.Photo, VkNet, Version=1.0.16.0, Culture=neutral, PublicKeyToken=null"
      }
    ]

How I may get value from "Photo604"? I want get picture url. Please Help me!

JNYRanger
  • 6,829
  • 12
  • 53
  • 81

1 Answers1

1

You need to cast Instance to a Photo first like this:

var photo = wall[0].Attachments[0].Instance as Photo
if (photo != null)
    var uri = photo.Photo604

Of course there is no error checking here. You should check for nulls and array lengths before accessing or you may get a null reference exception.

Kevin
  • 2,281
  • 1
  • 14
  • 16