Json过滤兄弟节点上的数据

时间:2017-05-11 11:18:57

标签: json jsonpath

我是JSONPath的新手,感谢任何帮助。我试图根据其兄弟值过滤数据。

我的JSON示例:

<ToggleButton HorizontalAlignment="Left" Margin="120,160,0,0" Padding="5" Width="65" FontWeight="Bold" FontSize="24" Click="capslockPressed" Uid="capslock"  Height="65" FontFamily="Calibri" VerticalAlignment="Top">
                    <ToggleButton.BorderBrush>
                        <LinearGradientBrush EndPoint="1,0" MappingMode="RelativeToBoundingBox" StartPoint="0,1">
                            <GradientStop Color="#FF7BC7CB"/>
                            <GradientStop Color="White" Offset="1"/>
                        </LinearGradientBrush>
                    </ToggleButton.BorderBrush>
                    <ToggleButton.Style>
                            <Style TargetType="{x:Type ToggleButton}">
                            <Setter Property="Content" Value="↑"  />
                            <Setter Property="Background" Value="#FF4C8389"/>
                            <Setter Property="Foreground" Value="White"/>
                            <Setter Property="Template">
                                <Setter.Value>
                                    <ControlTemplate TargetType="{x:Type ToggleButton}">
                                        <Border Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="3">
                                            <ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/>
                                        </Border>
                                    </ControlTemplate>
                                </Setter.Value>
                            </Setter>
                            <Style.Triggers>
                                <Trigger Property="IsMouseOver" Value="True">
                                </Trigger>
                                <Trigger Property="IsChecked" Value="True">
                                    <Setter Property="Content" Value="↑"/>
                                    <Setter Property="Background" Value="#9ec41d"/>
                                </Trigger>
                            </Style.Triggers>
                        </Style>
                    </ToggleButton.Style>
</ToggleButton>

我想通过名称查询id。我试过这样的事,但没有运气:

[

  {
  "id": "10300",
  "name": "NAME1"
  },
  {
  "id": "10500",
  "name": "NAME2"
  }
 ]

我确信我错过了一些微不足道的事情。

1 个答案:

答案 0 :(得分:2)

毕竟我自己找到了解决方案。

$..[?(@.name == 'NAME1')].id