[SOLVED] CS using System;

$25

File Name: CS_using_System;.zip
File Size: 150.72 KB

5/5 - (1 vote)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json;

namespace ConsoleApp1
{
class JsonFeed
{
static string _url = ;

public JsonFeed() { }
public JsonFeed(string endpoint, int results)
{
_url = endpoint;
}

public static string[] GetRandomJokes(string firstname, string lastname, string category)
{
HttpClient client = new HttpClient();
client.BaseAddress = new Uri(_url);
string url = jokes/random;
if (category != null)
{
if (url.Contains(?))
url += &;
else url += ?;
url += category=;
url += category;
}

string joke = Task.FromResult(client.GetStringAsync(url).Result).Result;

if (firstname != null && lastname != null)
{
int index = joke.IndexOf(Chuck Norris);
string firstPart = joke.Substring(0, index);
string secondPart = joke.Substring(0 + index + Chuck Norris.Length, joke.Length (index + Chuck Norris.Length));
joke = firstPart + + firstname + + lastname + secondPart;
}

return new string[] { JsonConvert.DeserializeObject (joke).value };
}

///

/// returns an object that contains name and surname
///

//////
public static dynamic Getnames()
{
HttpClient client = new HttpClient();
client.BaseAddress = new Uri(_url);
var result = client.GetStringAsync().Result;
return JsonConvert.DeserializeObject (result);
}

public static string[] GetCategories()
{
HttpClient client = new HttpClient();
client.BaseAddress = new Uri(_url);

return new string[] { Task.FromResult(client.GetStringAsync(categories).Result).Result };
}
}
}

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.

Shopping Cart
[SOLVED] CS using System;
$25