DataContractJsonSerializer를 사용하여 Flickr에서 일부 JSON 데이터를 구문 분석하려고합니다. JSON 응답을 받고 스트림에서 문제없이 계속 수행하고 있습니다. 파일에 쓰면 JSON이 모두 있습니다.DataContractJsonSerializer를 사용하여 JSON 응답을 구문 분석
jsonFlickrApi({"photos":{"page":1, "pages":372738, "perpage":10, "total":"3727375", "photo":[{"id":"9578613971", "owner":"[email protected]", "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
에서 아무 것도 얻을 code from msdn.microsoft.com/en-us/library/hh674188.aspx 이 단계를 완료하는 데 약간의 도움을 주시면 감사하겠습니다. 끝에서 "(JSON의 시작과에서") "jsonFlickrApi"를 제거
케이스 관련 있습니까? json은 소문자 값을 가지고 있습니다. 클래스는 파스칼 케이스입니다. –