I have the following code that works:
private string GetMovieCert(int ID)
{
try
{
var client = new RestClient("https://api.themoviedb.org/3/movie/" + ID.ToString() + "/release_dates?api_key=###");
var request = new RestRequest(Method.GET);
request.AddParameter("undefined", "{}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
List<char> items = response.Content.ToList<char>();
// Char version
int hit = 0;
string allres = "";
foreach (var item in items)
{
string f = item.ToString();
allres = allres + item.ToString();
if (f == "}")
{
if (allres.Contains("iso_3166_1\":\"US")) hit |= 3;
// if (allres.Contains("iso_3166_1")) hit |= 1;
// if (allres.Contains("US")) hit |= 2;
if (allres.Contains("\"certification\":\"\"")) hit |= 4;
if (hit == 3) break;
allres = "";
hit &= 3;
}
if (f == "]") hit = 0;
}
int pFrom = allres.IndexOf("certification") + "certification".Length;
int pTo = allres.LastIndexOf("iso_639_1");
String result = allres.Substring(pFrom, pTo - pFrom);
return result.Split(':')[1].Replace(",", "").Replace("\"", "");
}
catch { return ""; }
}
Is there a cleaner, more direct way to accomplish this? Using Linq or a JSON parser?
Thanks!
Nevari atrast filmu vai TV pārraidi? Jāpiesakās, lai to izveidotu.
Vēlies novērtēt šo vienumu vai pievienot to sarakstam?
Neesi dalībnieks?
Atbilde no RichGodlewski
on janvāris 2, 2017 at 12:08 PM
Ok, I figured out a way to retrieve a movie's certification using a JSON query. I'm posting the code so that it may help someone.
Atbilde no Travis Bell
on janvāris 2, 2017 at 1:34 PM
Hi @RichGodlewski Cool, thanks for the update. You'll find it always easier to use a real JSON parser as it will handle all of the proper serialization for you. Being able to work with native objects is always nicer 😃