我基本上是在开发台式机程序,我只是想在计时器或循环上收集信息,因此每次循环运行时,它都会保存instagram JSON提供的ID,然后继续上网,依此类推,我决定仅在Json instagram提供的单个图像上对此进行测试,如下所示。
{"pagination":{"next_max_tag_id":"1399847337728968","deprecation_warning":"next_max_id and min_id are deprecated for this endpoint; use min_tag_id and max_tag_id instead","next_max_id":"1399847337728968","next_min_id":"1399847337793336","min_tag_id":"1399847337793336","next_url":"https:\/\/api.instagram.com\/v1\/tags\/snow\/media\/recent?access_token=+49749273.8a6c775.3e8cf314d75045e49ba17263d0bededa\u0026count=1\u0026max_tag_id=1399847337728968"},"meta":{"code":200},"data":[{"attribution":null,"tags":["ilovenorway","hiking","spring","sunny","blaaskjerdigen","bluebird","cloud","clouds","redbullnorge","sun","visit","snow","aalesund","sunnm\u00f8rsalps","nofilter","norway","redbull"],"type":"image","location":{"latitude":62.595061667,"longitude":6.735158333},"comments":{"count":0,"data":[]},"filter":"Normal","created_time":"1399822137","link":"http:\/\/instagram.com\/p\/n3JFAHGTdZ\/","likes":{"count":0,"data":[]},"images":{"low_resolution":{"url":"http:\/\/origincache-ash.fbcdn.net\/10326375_690380867685736_1411474740_a.jpg","width":306,"height":306},"thumbnail":{"url":"http:\/\/origincache-ash.fbcdn.net\/10326375_690380867685736_1411474740_s.jpg","width":150,"height":150},"standard_resolution":{"url":"http:\/\/origincache-ash.fbcdn.net\/10326375_690380867685736_1411474740_n.jpg","width":640,"height":640}},"users_in_photo":[{"position":{"y":0.040625,"x":0.06535948},"user":{"username":"redbullnorge","profile_picture":"http:\/\/images.ak.instagram.com\/profiles\/profile_184192460_75sq_1342379531.jpg","id":"184192460","full_name":"Red Bull Norge"}},{"position":{"y":0.9609375,"x":0.06535948},"user":{"username":"redbull","profile_picture":"http:\/\/images.ak.instagram.com\/profiles\/profile_476322_75sq_1334010289.jpg","id":"476322","full_name":"Red Bull"}}],"caption":{"created_time":"1399822137","text":"#nofilter #blaaskjerdigen #bluebird #cloud #clouds #sun #sunny #hiking #snow #spring #ilovenorway #redbull #redbullnorge #visit #norway #aalesund #sunnm\u00f8rsalps","from":{"username":"jooakimandersen","profile_picture":"http:\/\/images.ak.instagram.com\/profiles \/profile_1246631612_75sq_1396821408.jpg","id":"1246631612","full_name":"Joakim Andersen"},"id":"718082592168556034"},"user_has_liked":false,"id":"718082591723960153_1246631612","user":{"username":"jooakimandersen","website":"","profile_picture":"http:\/\/images.ak.instagram.com\/profiles\/profile_1246631612_75sq_1396821408.jpg","full_name":"Joakim Andersen","bio":"","id":"1246631612"}}]}
我正在尝试从这样的json文件中获取信息
WebClient webClient = new WebClient();
var list = webClient.DownloadString("https://api.instagram.com/v1/tags/likeforlike/media/recent?access_token=" + Variables.authtoken + "&count=1");
dynamic parsedList = JsonConvert.DeserializeObject<dynamic>(list);
MessageBox.Show(parsedList.data.count.ToString());
但是我无法从中获得任何东西
MessageBox.Show(parsedList.data.ToString());
很好,但是我无法深入了解这些信息
最佳答案
使用json2csharp(http://json2csharp.com),我们生成了以下类。
public class Pagination
{
public string next_max_tag_id { get; set; }
public string deprecation_warning { get; set; }
public string next_max_id { get; set; }
public string next_min_id { get; set; }
public string min_tag_id { get; set; }
public string next_url { get; set; }
}
public class Meta
{
public int code { get; set; }
}
public class Location
{
public double latitude { get; set; }
public double longitude { get; set; }
}
public class Comments
{
public int count { get; set; }
public List<object> data { get; set; }
}
public class Likes
{
public int count { get; set; }
public List<object> data { get; set; }
}
public class LowResolution
{
public string url { get; set; }
public int width { get; set; }
public int height { get; set; }
}
public class Thumbnail
{
public string url { get; set; }
public int width { get; set; }
public int height { get; set; }
}
public class StandardResolution
{
public string url { get; set; }
public int width { get; set; }
public int height { get; set; }
}
public class Images
{
public LowResolution low_resolution { get; set; }
public Thumbnail thumbnail { get; set; }
public StandardResolution standard_resolution { get; set; }
}
public class Position
{
public double y { get; set; }
public double x { get; set; }
}
public class User
{
public string username { get; set; }
public string profile_picture { get; set; }
public string id { get; set; }
public string full_name { get; set; }
}
public class UsersInPhoto
{
public Position position { get; set; }
public User user { get; set; }
}
public class From
{
public string username { get; set; }
public string profile_picture { get; set; }
public string id { get; set; }
public string full_name { get; set; }
}
public class Caption
{
public string created_time { get; set; }
public string text { get; set; }
public From from { get; set; }
public string id { get; set; }
}
public class User2
{
public string username { get; set; }
public string website { get; set; }
public string profile_picture { get; set; }
public string full_name { get; set; }
public string bio { get; set; }
public string id { get; set; }
}
public class Datum
{
public object attribution { get; set; }
public List<string> tags { get; set; }
public string type { get; set; }
public Location location { get; set; }
public Comments comments { get; set; }
public string filter { get; set; }
public string created_time { get; set; }
public string link { get; set; }
public Likes likes { get; set; }
public Images images { get; set; }
public List<UsersInPhoto> users_in_photo { get; set; }
public Caption caption { get; set; }
public bool user_has_liked { get; set; }
public string id { get; set; }
public User2 user { get; set; }
}
public class RootObject
{
public Pagination pagination { get; set; }
public Meta meta { get; set; }
public List<Datum> data { get; set; }
}
然后,您应该能够使用JSON.NET反序列化为该结构。
var root = JsonConvert.DeserializeObject<RootObject>(list);
此时,只需拉出所需的属性即可。