Silverlight 및 .NET 아키텍처를 처음 사용합니다. Windows Phone 7 프로젝트에서 작업하고 있습니다. 서버에서 일부 JSON 형식 데이터를 수신합니다. WebClient 인터페이스 콜백에서 서버로부터 데이터를받습니다. 그러나 C# 개체의 데이터를 serialize 할 수 없습니다. 나는 다음 코드를 사용하고DeSerializing complex json wp7
public void GetData_Completed(object sender, DownloadStringCompletedEventArgs e)
{
byte[] encodedString = Encoding.UTF8.GetBytes(e.Result);
//// Put the byte array into a stream and rewind it to the beginning
MemoryStream ms = new MemoryStream(encodedString);
ms.Flush();
ms.Position = 0;
// convert json result to model
Stream stream = ms;
DataContractJsonSerializer dataContractJsonSerializer = new DataContractJsonSerializer(typeof(SchedulesResults));
SchedulesResults myResults =
(SchedulesResults)dataContractJsonSerializer.ReadObject(stream);
var result = myResults;
}
내가 얻을 가정하고 데이터 형식이
schedules: [
{
id: 2897
progress: -9
state: complete
starts_at: 1315267800
primary_topic: {
id: 13
}
secondary_topic: {
id: 9
}
scores: [
{
schedule_id: 2897
score: 0
topic_id: 13
}
{
schedule_id: 2897
score: 4
topic_id: 9
}
]
}
.
.
.
처럼이 내가 serilaize에게
public class SchedulesResults
{
/// <summary>
/// Gets or sets the results.
/// </summary>
/// <value>The results.</value>
public Schedules[] results { get; set; }
}
public class Schedules
{
int id { get; set; }
int progress { get; set; }
string state { get; set; }
DateTime starts_at { get; set; }
primary_topic primary_topic_ID { get; set; }
secondry_topic secondary_topic_ID { get; set; }
Scores[] scores { get; set; }
}
public class primary_topic
{
int id { get; set; }
}
public class secondry_topic
{
int id { get; set; }
}
public class Scores
{
int schedule_id{ get; set; }
int score { get; set; }
int topic_id { get; set; }
}
을 해제하기 위해 사용하고있는 클래스입니다
하지만 내가 값에 null이 점점 직렬화에. 어디에서 잘못 될지 말해주세요.
이
데이터의 종류는 내가 서버에서 얻고있다 당신은 그것이해야처럼 보인다 (사용할 수있는 코드에서), 시도하고MyCLASS
의 인스턴스로 응답을 역 직렬화하지만 것처럼 보이는 것
{"schedules":[{"id":3499,"progress":-9,"state":"complete","starts_at":1317945600,"primary_topic":{"id":6},"secondary_topic":{"id":11},"scores":[{"schedule_id":3499,"score":2,"topic_id":6},{"schedule_id":3499,"score":3,"topic_id":11}]},
이 생성 도움이 될 마시고의 : HTTP : //json2csharp.com/ –
덕분에 많은 데릭 ... 그것은 효과가 있었다. – Avijeet