开发者

Getting a value from a nested JSON structure by property name

Say I have a JSON structure that describes a collection of quotes as shown below (this is just showing the first quote).

How do I get the Description for the Benefit named "More legroom" in the first quote.

<Quotes>
  <Quote>
    <Price>1.50</Price>
    <Benefits>
      <Benefit>
        <Name>Free Meals</Name>
        <Description>Get Free Meals on every journey</Description>
      <Benefit>
      <Benefit>
        <Name>More legroom</Name>
        <Description>Get more leg room on every journey</Description>
      <Benefit>
      <Benefit>
        <Name>Free Drinks</Name>
        <Description>Get Free Drinks on every journey</Description>
      &l开发者_如何学Pythont;Benefit>
    </Benefits>
  </Quotes>
<Quote>


    for (var i = 0; i < quotes[0].Benefits.length; i++) {
        if (jQuery.trim(quotes[0].Benefits[i].Name == "More legroom")) {
            benefitDescription = quotes[0].Benefits[i].Description
        }
    }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜