如果我的回复有关键"错误",我需要处理错误并显示警告框.
json.net中是否存在"haskey"方法?喜欢:
var x= JObject.Parse(string_my);
if(x.HasKey["error_msg"])
MessageBox.Show("Error!")
Run Code Online (Sandbox Code Playgroud) 我正在使用JSON.NET使用.NET解析来自openexhangerates.org服务器端的JSON响应.响应包含一个嵌套对象("rates"),它有一长串数字属性:
{
"disclaimer": "Exchange rates provided for informational purposes only, with no guarantee whatsoever of accuracy, validity, availability, or fitness for any purpose; use at your own risk. Other than that, have fun! Usage subject to acceptance of terms: http://openexchangerates.org/terms/",
"license": "Data sourced from various providers with public-facing APIs; copyright may apply; not for resale; no warranties given. Usage subject to acceptance of license agreement: http://openexchangerates.org/license/",
"timestamp": 1357268408,
"base": "USD",
"rates": {
"AED": 3.673033,
"AFN": 51.5663,
"ALL": 106.813749,
"AMD": 403.579996, …Run Code Online (Sandbox Code Playgroud) 我有一个 JSON 对象:
{
""settings"": {
""general"": {
""database"": { ""type"": ""PostgreSql"" }
}
}
}
Run Code Online (Sandbox Code Playgroud)
我的 JSON 对象的绝对路径如下所示:settings/general/database/type
我试图用这个问题的第一个解决方案获取所有密钥:
IList<string> keys = parent.Properties().Select(p => p.Name).ToList();
Run Code Online (Sandbox Code Playgroud)
这对我不起作用。该keys列表只包含第一个密钥settings,没有其他密钥。
有一个path属性显示您所在节点的路径,但它不显示 JSON 对象的完整路径。
如何获得像我的示例中那样的绝对路径?