【发布时间】:2016-07-12 20:56:06
【问题描述】:
例如,我有 Jobject:
string json = @"
{
""memberdetails"": [
{
""id"": 0,
""label"": ""General Details"",
""visible"": true,
""properties"": [
{
""label"": ""Address"",
""description"": ""Residential or Postal Address"",
""view"": ""textarea"",
""config"": {},
""hideLabel"": false,
""validation"": {
""mandatory"": false,
""pattern"": null
},
""id"": 0,
""value"": ""test 1"",
""alias"": ""address"",
""editor"": ""Umbraco.TextboxMultiple"",
""visible"": ""true""
},
{
""label"": ""State"",
""description"": ""State of residence"",
""view"": ""textbox"",
""config"": {},
""hideLabel"": false,
""validation"": {
""mandatory"": false,
""pattern"": null
},
""id"": 0,
""value"": ""test 2"",
""alias"": ""state"",
""editor"": ""Umbraco.Textbox"",
""visible"": ""true""
}
]
},
{
""id"": 1,
""label"": ""Other Details"",
""visible"": true,
""properties"": [
{
""label"": ""Address"",
""description"": ""Residential or Postal Address"",
""view"": ""textarea"",
""config"": {},
""hideLabel"": false,
""validation"": {
""mandatory"": false,
""pattern"": null
},
""id"": 0,
""value"": ""test_otherdetails1 "",
""alias"": ""address"",
""editor"": ""Umbraco.TextboxMultiple"",
""visible"": ""true""
},
{
""label"": ""State"",
""description"": ""State of residence"",
""view"": ""textbox"",
""config"": {},
""hideLabel"": false,
""validation"": {
""mandatory"": false,
""pattern"": null
},
""id"": 0,
""value"": ""test_otherdetails2"",
""alias"": ""state"",
""editor"": ""Umbraco.Textbox"",
""visible"": ""true""
}
]
},
{
""id"": 2,
""label"": "" Details"",
""visible"": true,
""properties"": [
{
""label"": ""Address"",
""description"": ""Residential or Postal Address"",
""view"": ""textarea"",
""config"": {},
""hideLabel"": false,
""validation"": {
""mandatory"": false,
""pattern"": null
},
""id"": 0,
""value"": "" Details1"",
""alias"": ""address"",
""editor"": ""Umbraco.TextboxMultiple"",
""visible"": ""true""
},
{
""label"": ""State"",
""description"": ""State of residence"",
""view"": ""textbox"",
""config"": {},
""hideLabel"": false,
""validation"": {
""mandatory"": false,
""pattern"": null
},
""id"": 0,
""value"": ""Details1"",
""alias"": ""state"",
""editor"": ""Umbraco.Textbox"",
""visible"": ""true""
}
]
}
]
}";
我想得到如下json格式的“别名”和“值”的值
[
{"address": "test"},
{"state": "test"}
]
那么,json.net 中是否有任何内置方法可以让我获得特定的属性值?
或者我是否需要在 c# 中实现一些递归方法,该方法将在 JObject 中的所有 JToken 和 JArray 中按名称搜索 JToken? 有什么建议吗?
谢谢,
【问题讨论】:
-
你试过这个reference 吗?
-
是的,我正在检查它但是我的结果集有点不同,其中一个属性“alias”的值是“state”是“value”的属性,即“test”......示例代码是:'code'“id”:0,“value”:“test”,“alias”:“state”,“editor”:“Umbraco.Textbox”,“visible”:“true”},跨度>