【发布时间】:2020-10-30 19:50:43
【问题描述】:
我有一个用 python 编写的代码的 sn-p,我必须在 Newtonsoft JSON 的帮助下将其重写为 C#
def getconfig():
with open("config.json") as f:
return json.loads(f.read())
并且我必须能够访问代码中 JSON 的元素,就像它在这个 sn-p 中显示的那样
def getcaptcha(proxy):
while(True):
ret = s.get("{}{}&pageurl={}"
.format(getconfig()['host'], getconfig()['key'], getconfig()['googlekey'], getconfig()['pageurl'])).text
到目前为止,我已经提出了这个想法:
public bool GetConfig()
{
JObject config = JObject.Parse(File.ReadAllText("path/config.json"));
using (StreamReader file = File.OpenText("path/config.json"))
using (JsonTextReader reader = new JsonTextReader(file))
{
JObject getConfig = (JObject) JToken.ReadFrom(reader);
}
return true;
}
但它似乎不起作用,因为我无法在进一步的代码中访问它
GetConfig()['host']
例如。我什至不能 Console.WriteLine 我的 JSON
【问题讨论】:
-
在 C# 中,字符串用双引号括起来,例如“host”,而不是“host”。如果你尝试 'host',你应该会得到一个编译错误。
标签: python c# .net windows performance