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!

4
  • 5
    Why are you serializing the collection at all? Why not just get wall[0].Attachments[0].Instance.Photo604? Commented Jun 12, 2015 at 18:25
  • Can you show the Post type? Commented Jun 12, 2015 at 18:55
  • Yes, it's Post type Commented Jun 12, 2015 at 19:04
  • that is not a valid json string; you may have broke it making it anonymous Commented Jun 12, 2015 at 19:33

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.