Прежде всего, вам нужно написать класс для сериализации ответного объекта json.
В этом случае этот API возвращает json следующим образом:
{
"page": int,
"total_results": int,
"total_pages": int,
"results": [
{
"vote_count": int,
"id": int,
"video": bool,
"vote_average": float,
"title": string,
"popularity": double,
"poster_path": string,
"original_language": string,
"original_title": string,
"genre_ids": [
int
],
"backdrop_path": string,
"adult": bool,
"overview": string,
"release_date": string
}
]
}
Итак, ваш класс Serializable (es) должен выглядеть следующим образом:
[Serializable]
public class Movies
{
public int page { get; set; }
public int total_results { get; set; }
public int total_pages { get; set; }
public List<Result> results { get; set; }
}
[Serializable]
public class Result
{
public int vote_count { get; set; }
public int id { get; set; }
public bool video { get; set; }
public double vote_average { get; set; }
public string title { get; set; }
public double popularity { get; set; }
public string poster_path { get; set; }
public string original_language { get; set; }
public string original_title { get; set; }
public IList<int> genre_ids { get; set; }
public string backdrop_path { get; set; }
public bool adult { get; set; }
public string overview { get; set; }
public string release_date { get; set; }
}
После этого вы можете легко десериализовать объект json, вот пример кода:
IEnumerator FetchMovies(string movieName)
{
WWW www = new WWW(url+"search/movie?api_key="+apiKey+"&query="+movieName);
yield return www;
if(www.error==null)
{
var movies = Newtonsoft.Json.JsonConvert.DeserializeObject<Movies>(www.text);
foreach(var movie in movies.results)
{
Debug.Log("Title " + movie.title);
Debug.Log("Overview " + movie.overview);
}
}
else
{
Debug.LogError(www.error);
}
}