从Instagram API中检索从JSON字符串中检索"图像"

ali*_*ali 2 c# json json.net instagram

使用C#和Visual Studio 2010(Windows窗体项目),InstaSharp和Newtonsoft.Json库.

当我请求特定的主题标签时,我想从Endpoint Instagram API 返回给我的JSON字符串中获取图像URL.

到目前为止我可以检索JSON字符串.

我试图使用Newtonsoft.Json使用示例反序列化对象,但我可能不正确理解对象的JSON字符串表示.

下面是responsetags/tag-name/media/recent从他们的文档中的api调用获得的简化示例.来源于此

{
    "data": [{
        "type": "image",
        "filter": "Earlybird",
        "tags": ["snow"],
        "comments": {
        }
        "caption": {
        },
        "likes": {
        },
        "created_time": "1296703536",
        "images": {
            "low_resolution": {
                "url": "http://distillery.s3.amazonaws.com/media/2011/02/02/f9443f3443484c40b4792fa7c76214d5_6.jpg",
                "width": 306,
                "height": 306
            },
            "thumbnail": {
                "url": "http://distillery.s3.amazonaws.com/media/2011/02/02/f9443f3443484c40b4792fa7c76214d5_5.jpg",
                "width": 150,
                "height": 150
            },
            "standard_resolution": {
                "url": "http://distillery.s3.amazonaws.com/media/2011/02/02/f9443f3443484c40b4792fa7c76214d5_7.jpg",
                "width": 612,
                "height": 612
            }
        },
        "id": "22699663",
        "location": null
    },
    ...
    ]
}
Run Code Online (Sandbox Code Playgroud)

我想特别是standard_resolutionimages部分.

这是我目前拥有的相关代码.

//Create the Client Configuration object using Instasharp
var config = new InstaSharp.Endpoints.Tags.Unauthenticated(config);

//Get the recent pictures of a particular hashtag (tagName)
var pictures = config.Recent(tagName);

//Deserialize the object to get the "images" part
var pictureResultObject = JsonConvert.DeserializeObject<dynamic>(pictureResult.Json);
            consoleTextBox.Text = pictureResult.Json;
            var imageUrl = pictureResultObject.Data.Images;
            Console.WriteLine(imageUrl);
Run Code Online (Sandbox Code Playgroud)

我收到错误: Additional information: Cannot perform runtime binding on a null reference

所以imageUrl当我调试时确实为null,因此表明我没有以正确的方式访问它.

任何人都可以向我解释如何使用Newtonsoft.Json访问此JSON字符串的不同部分?

L.B*_*L.B 5

使用 Newtonsoft.Json

dynamic dyn = JsonConvert.DeserializeObject(json);
foreach (var data in dyn.data)
{
    Console.WriteLine("{0} - {1}",
            data.filter,
            data.images.standard_resolution.url);
}
Run Code Online (Sandbox Code Playgroud)