protected override void OnNavigatedTo(NavigationEventArgs e) { postInfo_list.ItemsSource = CommentList; pid = (int)e.Parameter; HttpRequestAsync(async () => { string resourceAddress = postServer + pid; string responseBody; HttpResponseMessage response = await httpClient.GetAsync(new Uri(resourceAddress)).AsTask(cts.Token); responseBody = await response.Content.ReadAsStringAsync().AsTask(cts.Token); var serializer = new DataContractJsonSerializer(typeof(postInfo)); //将json字符串解析成class var mStream = new MemoryStream(Encoding.Unicode.GetBytes(responseBody)); postinfo = (postInfo)serializer.ReadObject(mStream); init_post(postinfo.post); resourceAddress = commentServer + pid; response = await httpClient.GetAsync(new Uri(resourceAddress)).AsTask(cts.Token); responseBody = await response.Content.ReadAsStringAsync().AsTask(cts.Token); serializer = new DataContractJsonSerializer(typeof(floorInfo)); //将json字符串解析成class mStream = new MemoryStream(Encoding.Unicode.GetBytes(responseBody)); floors = (floorInfo)serializer.ReadObject(mStream); init_comment(floors); return responseBody; }); }
public void init_comment(floorInfo floors) { int i; for (i = 0; i < floors.floorSum; i++) CommentList.Add(new Floors { created_at=floors.floors[i].created_at, content = floors.floors[i].content }); }