Here is my prompt:
Retrieve a JSON file from a remote URL. Your solutions should pull this from a settings file (app.config, web.config. etc). (I have the url)
Determine if a provided string is a palindrome. Alphanumeric chars will be considered when evaluating whether or not the string is a palindrome.
- Parse the retrieved JSON file, and pass each element in the "strings" array, into the function in step #2. You should print out the string and result.
I am new to C# and I am having trouble figuring out how to read the json file from the url, and then using it for the function. I am pretty much stuck on how to start this. Any tips?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net;
namespace ConsoleApplication1
{
class Program
{
public static bool IsPalindrome(string value)
{
int min = 0;
int max = value.Length - 1;
// while (true)
{
if (min > max)
{
return true;
}
char a = value[min];
char b = value[max];
if (char.ToLower(a) != char.ToLower(b))
{
return false;
}
min++;
max--;
}
}
static void Main() {
using (WebClient webClient = new System.Net.WebClient())
{
WebClient n = new WebClient();
var json = n.DownloadString("URL");
string valueOriginal = Convert.ToString(json);
//Console.WriteLine(json);
}
string[] array = {
};
foreach (string value in array)
{
Console.WriteLine("{0} = {1}", value, IsPalindrome(value));
}
}
}
}
Sample JSON:
{
"strings": [
{
"str": "mom",
"result": "true"
},
{
"str": "Taco Cat",
"result": "true"
},
{
"str": "university",
"result": "false"
},
{
"str": "Amore, Roma.",
"result": "true"
},
{
"str": "King are you glad you are king",
"result": "false"
}
]
}