使用DataContractJsonSerializer解析Flickr JSON响应

本文关键字:JSON 响应 Flickr 解析 DataContractJsonSerializer 使用 | 更新日期: 2023-09-27 18:28:47

所以我试图使用DataContractJsonSerializer解析Flickr中的一些JSON数据我收到了JSON响应,并将其保存在流中,这意味着我已经通过写入文件来传递它进行了测试,JSON就在那里。

jsonFlickrApi({"photos":{"page":1, "pages":372738, "perpage":10, "total":"3727375", "photo":[{"id":"9578613971", "owner":"7960563@N07", "secret":"b7b80b75f8", "server":"3734", "farm":4, "title":"1970 - 1978 Toyota Corolla E20 Coup'u00e9", "ispublic":1, "isfriend":0, "isfamily":0, "url_t":"http:'/'/farm4.staticflickr.com'/3734'/9578613971_b7b80b75f8_t.jpg", "height_t":"67", "width_t":"100", "url_o":"http:'/'/farm4.staticflickr.com'/3734'/9578613971_0eda23bccb_o.jpg", "height_o":"1000", "width_o":"1500"}}]}, "stat":"ok"})

但是,当我尝试使用Jsonserializer进行解析时,我注意到它不包含任何内容。

感谢Json2Cshap.com ,我已经通过合同类建立了

public class ResponseContract
{
    [DataContract]
    public class Photo
    {
        [DataMember]
        public string id { get; set; }
        [DataMember]
        public string owner { get; set; }
        [DataMember]
        public string secret { get; set; }
        [DataMember]
        public string server { get; set; }
        [DataMember]
        public int farm { get; set; }
        [DataMember]
        public string title { get; set; }
        [DataMember]
        public string url_t { get; set; }
        [DataMember]
        public string url_o { get; set; }
    }
    [DataContract]
    public class Photos
    {
        [DataMember]
        public int page { get; set; }
        [DataMember]
        public int pages { get; set; }
        [DataMember]
        public int perpage { get; set; }
        [DataMember]
        public string total { get; set; }
        [DataMember]
        public List<Photo> photoList { get; set; }
    }
    [DataContract]
    public class RootObject
    {
        [DataMember]
        public Photos photos { get; set; }
        [DataMember]
        public string stat { get; set; }
    }

我的代码是这样的:

            // Creates an HttpWebRequest with the specified URL. 
        HttpWebRequest request = (HttpWebRequest)WebRequest.Create(this.longUrl);
        // Send the request and wait for response.          
        HttpWebResponse response = (HttpWebResponse)request.GetResponse();
        // Get the response stream
        Stream responseStream = response.GetResponseStream();
        DataContractJsonSerializer jsonSerializer = new DataContractJsonSerializer(typeof(Photos));
        object objResponse = (Photos)jsonSerializer.ReadObject(responseStream);
        Photos jsonResponse = objResponse as Photos;
        response.Close();

但我在jsonResponse 中一无所获

从msdn.microsoft.com/en-us/library/hh674188.aspx获取部分代码如果能帮我渡过这一步,我将不胜感激。

使用DataContractJsonSerializer解析Flickr JSON响应

尝试从末尾删除"jsonFlickrApi("from JSON start and")"。。

我认为您正在向API发送一个回调参数,这里不需要,因为您不使用JavaScript来解析响应