我将集合转换为JSON字符串。
ReadOnlyCollection<Post> wall = api.Wall.Get(-group.Id.Value, out totalCount, count);
string json = JsonConvert.SerializeObject(wall, Formatting.Indented);
像这样获取字符串 JSON
[
{
"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"
}
]
如何从"Photo604"中获得价值?我想要获取图片网址。请帮助我!
您需要
先将实例投射到照片中,如下所示:
var photo = wall[0].Attachments[0].Instance as Photo
if (photo != null)
var uri = photo.Photo604
当然,这里没有错误检查。在访问之前,您应该检查空值和数组长度,否则可能会收到空引用异常。