private static kcsapi_ranking_getlist Serialize(Session session) { try { var djson = DynamicJson.Parse(session.GetResponseAsJson()); var rankings = new kcsapi_ranking_getlist { api_count = Convert.ToInt32(djson.api_data.api_count), api_disp_page = Convert.ToInt32(djson.api_data.api_disp_page), api_page_count = Convert.ToInt32(djson.api_data.api_page_count), }; var list = new List<kcsapi_ranking>(); var serializer = new DataContractJsonSerializer(typeof(kcsapi_ranking)); foreach (var x in (object[])djson.api_data.api_list) { try { list.Add(serializer.ReadObject(new MemoryStream(Encoding.UTF8.GetBytes(x.ToString()))) as kcsapi_ranking); } catch (SerializationException ex) { Debug.WriteLine(ex.Message); } } rankings.api_list = list.ToArray(); return rankings; } catch (Exception ex) { Debug.WriteLine(ex); return null; } }
private static kcsapi_questlist Serialize(Session session) { try { var djson = DynamicJson.Parse(session.GetResponseAsJson()); var questlist = new kcsapi_questlist { api_count = Convert.ToInt32(djson.api_data.api_count), api_disp_page = Convert.ToInt32(djson.api_data.api_disp_page), api_page_count = Convert.ToInt32(djson.api_data.api_page_count), api_exec_count = Convert.ToInt32(djson.api_data.api_exec_count), }; var list = new List<kcsapi_quest>(); var serializer = new DataContractJsonSerializer(typeof(kcsapi_quest)); foreach (var x in (object[])djson.api_data.api_list) { try { list.Add(serializer.ReadObject(new MemoryStream(Encoding.UTF8.GetBytes(x.ToString()))) as kcsapi_quest); } catch (SerializationException ex) { // 最後のページで任務数が 5 に満たないとき、api_list が -1 で埋められるというクソ API のせい Debug.WriteLine(ex.Message); } } questlist.api_list = list.ToArray(); return questlist; } catch (Exception ex) { Debug.WriteLine(ex); return null; } }