private static ThreadContainer parse_ffuuka_json(FoolFuukaParserData ffp_data) { ThreadContainer tc = null; string data = fetch_api(ffp_data); JsonObject response = JsonConvert.Import <JsonObject>(data); JsonObject threadObject = (JsonObject)response[ffp_data.ThreadID.ToString()]; JsonObject opPost = (JsonObject)threadObject["op"]; tc = new ThreadContainer(parse_thread(opPost, ffp_data)); JsonObject postsObject = (JsonObject)threadObject["posts"]; foreach (string reply_id in postsObject.Names.Cast <string>()) { JsonObject replyObject = (JsonObject)postsObject[reply_id]; GenericPost reply = parse_reply(replyObject, ffp_data); tc.AddReply(reply); continue; } return(tc); }
public ThreadContainer GetThreadData(string board, int id) { APIResponse response = LoadAPI(string.Format("{0}://a.4cdn.org/{1}/thread/{2}.json", Common.HttpPrefix, board, id)); switch (response.Error) { case APIResponse.ErrorType.NoError: ThreadContainer tc = null; JsonObject list = JsonConvert.Import <JsonObject>(response.Data); //if (list == null) //{ // FlushAPI(string.Format("http://a.4cdn.org/{0}/thread/{1}.json", board, id)); // return GetThreadData(board, id); //} if (list.Names.Cast <string>().Contains("posts")) { JsonArray data = list["posts"] as JsonArray; tc = new ThreadContainer(ParseThread((JsonObject)data.First(), board)); for (int index = 1; index < data.Count; index++) { tc.AddReply(ParseReply((JsonObject)data[index], board)); } } return(tc); case APIResponse.ErrorType.NotFound: throw new Exception("404"); case APIResponse.ErrorType.Other: throw new Exception(response.Data); default: return(null); } }