Example #1
0
        public JsonResult GetCharacters()
        {
            string  json = SendRequest("https://swapi.dev/api/people");
            JObject data = JObject.Parse(json);

            GetCharacterlist list = new GetCharacterlist();

            List <GetCharacterlist> tempList = new List <GetCharacterlist>();

            for (int i = 0; i < data["results"].Count(); i++)
            {
                GetCharacterlist x = new GetCharacterlist();
                x.name = (string)data["results"][i]["name"];
                x.id   = i + 1;             //id for specific characters

                tempList.Add(x);
            }

            return(Json(tempList, JsonRequestBehavior.AllowGet));
        }
Example #2
0
        //Create method in CharactersController to retrieve information of a specific Star Wars characters
        public JsonResult SpecificCharacters(string id)
        {
            string  json = SendRequest("https://swapi.dev/api/people/" + id);
            JObject data = JObject.Parse(json);

            GetCharacterlist current = new GetCharacterlist();

            current.name = (string)data["name"];

            CharacterInfo x = new CharacterInfo();

            x.name       = (string)data["name"];
            x.height     = (string)data["height"];
            x.mass       = (string)data["mass"];
            x.hair_color = (string)data["hair_color"];
            x.skin_color = (string)data["skin_color"];
            x.eye_color  = (string)data["eye_color"];
            x.birth_year = (string)data["birth_year"];
            x.gender     = (string)data["gender"];

            return(Json(x, JsonRequestBehavior.AllowGet));
        }