当存在多个值时,JSON.Net SelectToken不返回Jtokens

问题描述 投票:1回答:2

我具有以下JSON结构,并且我试图在“ prototypequery”下获取所有“属性”值。在此示例中,我想获取“名称”,“领导”,“联系人”,“年份”。

我尝试通过使用jsonobject.SelectTokens(“ prototypeQuery.Select..Property”,false)来获取此信息,但查询未返回任何Jtoken。我在foreach循环中使用了它,但它从未进入循环。

foreach (var item in jsonobject.SelectTokens("prototypeQuery.Select..Property", false))

还有其他方法可以获取所有“属性”值列表吗?

"prototypeQuery":{
     "Version":2,
     "From":[
        {
           "Name":"i",
           "Entity":"IPS"
        }
     ],
     "Select":[
        {
           "Column":{
              "Expression":{
                 "SourceRef":{
                    "Source":"i"
                 }
              },
              "Property":"Name"
           },
           "Name":"IPS.Name"
        },
        {
           "Column":{
              "Expression":{
                 "SourceRef":{
                    "Source":"i"
                 }
              },
              "Property":"Lead"
           },
           "Name":"IPS.Lead"
        },
        {
           "Column":{
              "Expression":{
                 "SourceRef":{
                    "Source":"i"
                 }
              },
              "Property":"Contact"
           },
           "Name":"IPS.Contact"
        },
        {
           "Column":{
              "Expression":{
                 "SourceRef":{
                    "Source":"i"
                 }
              },
              "Property":"Year"
           },
           "Name":"IPS.Year"
        }
     ]
  }
c# json json.net jsonpath
2个回答
0
投票

[选择为数组,属性为列的字段,您可能想摆脱使用递归下降运算符,而将它专门用于数组。

$。prototypeQuery.Select [*]。Column.Property

给我正确的值。


0
投票

将其转换为Jtoken列表对我有用

IList<JToken> items = json.SelectTokens("prototypeQuery.Select..Property", false).ToList();
© www.soinside.com 2019 - 2024. All rights reserved.