解析包含嵌套对象的JSON

我是angularjs的新手。我在读取包含嵌套对象的JSON时遇到问题。我能够读取cartItems内的数量,费率和数量,但无法读取商品内的shortDescription。

我的JSON是:

{
"_links": {
    "search": {
        "href": "http://localhost:8080/sportsrest/cartItems/search"
    }
},
"_embedded": {
    "cartItems": [
        {
            "rate": 500,
            "quantity": 1,
            "amount": 500,
            "_embedded": {
                "merchandise": {
                    "shortDescription": "test description1 ",
                    "rate": 500
                }
            },
            "_links": {
                "self": {
                    "href": "http://localhost:8080/sportsrest/cartItems/801"
                }
            }
        },
        {
            "rate": 1000,
            "quantity": 2,
            "amount": 2000,
            "_embedded": {
                "merchandise": {
                    "shortDescription": "test description2",
                    "rate": 1000
                }
            },
            "_links": {
                "self": {
                    "href": "http://localhost:8080/sportsrest/cartItems/802"
                }
            }
        }
    ]
}
} 

在我的html页面中,我解析为:

   <tr ng-repeat="cart in cartItems._embedded.cartItems">
                <td>{{cart.quantity}}</td>
                <div ng-repeat="item in cart._embedded.merchandise">
                    <td> {{item.shortDescription}}</td></div>
                <td>{{cart.rate}}</td>
                <td>{{cart.amount}}</td>
            </tr>

任何人都可以解决我的问题。在此先感谢您。

鲁勒
<tr ng-repeat="cart in cartItems._embedded.cartItems">
   <td>{{cart.quantity}}</td>
   <td>{{cart._embedded.merchandise.shortDescription}}</td><td>{{cart.rate}}  </td>
   <td>{{cart.amount}}</td>
</tr>

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章