c# - Parsing Flickr JSON Responses with DataContractJsonSerializer -
so i'm trying parse json data flickr using datacontractjsonserializer i'm receiving json response , keeping in stream no problems, meaning have tested passing writing file , json there.
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"})
but when try parse using jsonserializer instead notice doesn't contain anything.
i have established contract class 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; } }
and code looks this:
// creates httpwebrequest specified url. httpwebrequest request = (httpwebrequest)webrequest.create(this.longurl); // send request , wait response. httpwebresponse response = (httpwebresponse)request.getresponse(); // response stream stream responsestream = response.getresponsestream(); datacontractjsonserializer jsonserializer = new datacontractjsonserializer(typeof(photos)); object objresponse = (photos)jsonserializer.readobject(responsestream); photos jsonresponse = objresponse photos; response.close();
but nothing in jsonresponse
got of code msdn.microsoft.com/en-us/library/hh674188.aspx little me on step appreciated.
try removing "jsonflickrapi(" json start , ")" end..
i think sending callback param api don't need here, since not using javascript parse response
Comments
Post a Comment