1
I’m studying API access and I’m using the Github API. I want to make a screen in which it is possible to search by name the repositories that match the criteria passed. But Github’s results are huge, as I can do to paginate that list?
Now I’m having trouble reading the JSON returned by the search. In the code below is the class that accesses the API and downloads the JSON
public List<Repositorio> PesquisaRepo(string repoNome) {
List<Repositorio> repositorios = new List<Repositorio>();
string urlPesquisa = urlPesquisaRepo + repoNome;
var client = new WebClient();
client.Headers.Add("user-agent", this.userAgent);
var resposta = client.DownloadString(urlPesquisa);
var repoJSON = JArray.Parse(resposta);
}
On the line var repoJSON = JArray.Parse(resposta);
the following error occurs:
Error reading JArray from JsonReader. Current JsonReader item is not an array
The returned JSON is in this format:
{
"total_count": 18551,
"incomplete_results": false,
"items": [
{
"id": 76954504,
"node_id": "MDEwOlJlcG9zaXRvcnk3Njk1NDUwNA==",
"name": "react-tetris",
"full_name": "chvin/react-tetris",
"owner": {
"login": "chvin",
"id": 5383506,
"node_id": "MDQ6VXNlcjUzODM1MDY=",
"avatar_url": "https://avatars2.githubusercontent.com/u/5383506?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/chvin",
"html_url": "https://github.com/chvin",
"followers_url": "https://api.github.com/users/chvin/followers",
"following_url": "https://api.github.com/users/chvin/following{/other_user}",
"gists_url": "https://api.github.com/users/chvin/gists{/gist_id}",
"starred_url": "https://api.github.com/users/chvin/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/chvin/subscriptions",
"organizations_url": "https://api.github.com/users/chvin/orgs",
"repos_url": "https://api.github.com/users/chvin/repos",
"events_url": "https://api.github.com/users/chvin/events{/privacy}",
"received_events_url": "https://api.github.com/users/chvin/received_events",
"type": "User",
"site_admin": false
How do I access only the "items tag"?
The URL I’m accessing is https://api.github.com/search/repositories?q=tetris
post the part of the code where it is difficult, so we can help you.
– Luciano Azevedo
@Marconi Compiler indicates error
– Leandro Souza
You have the json class ?
– Matheus Miranda
@Matheusmiranda The class to create objects with this JSON? I have a class called Repositorio that has some attributes that I want to recover from JSON
– Leandro Souza
@Marconi tried this. He says "answer" is a string and has no settings to access a method
– Leandro Souza
@Leandrosouza, I understand see my answer.
– Matheus Miranda