I want to decode a simple json array using C# that's stored in a GitHub repo to see if it contains a value. I'm using the Newtonsoft json package. I've read this thread: Code for decoding/encoding a modified base64 URL, but I can't seem to implement the solution. I get the following error:
System.FormatException: The input is not a valid Base-64 string as it contains a non-base 64 character, more than two padding characters, or an illegal character among the padding characters
, but I think there's also something going on with the code.
var value = "somestring";
var encodedTopicTypeURL ="https://api.github.com/repos/org/repo1/contents/sample.json";
string decodedTopicTypeURL;
byte[] buffer = Convert.FromBase64String(encodedTopicTypeURL);
decodedTopicTypeURL = Encoding.UTF8.GetString(buffer);
using (var webClient = new System.Net.WebClient())
{
var topicTypeJson = webClient.DownloadString(decodedTopicTypeURL);
JArray validTopicTypes = JArray.Parse(topicTypeJson);
if (!validTopicTypes.Contains(value))
{
Logger.LogError($"Value not found");
}
Json array:
[
"string1",
"string2",
"string3",
"string4",
]