【发布时间】:2016-08-16 06:02:56
【问题描述】:
我想使用 C# 对存储在 GitHub 存储库中的简单 json 数组进行解码,以查看它是否包含值。我正在使用 Newtonsoft json 包。我读过这个帖子:Code for decoding/encoding a modified base64 URL,但我似乎无法实现该解决方案。我收到以下错误:
System.FormatException:输入不是有效的 Base-64 字符串,因为它包含非 base 64 字符、两个以上的填充字符, 或填充字符中的非法字符
,但我认为代码也有问题。
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 数组:
[
"string1",
"string2",
"string3",
"string4",
]
【问题讨论】: