如何通过循环使用jquery在网页上显示json数据?

时间:2016-09-17 06:48:53

标签: jquery json loops

我创建了一个json,我必须通过循环在服务器上显示它。我在该建筑物下面有一些建筑物数据,有一些楼层,有些房间下面有一些房子,下面有一些床。 我必须使用循环在网页上显示它。

{
    "property_data": [{
            "building_id": "b001",
            "building_title": "B1",
            "building_project": "A",
            "building_address": "Beside Fathima School, Keshwapur",
            "building_stats": {
                "floors": 7,
                "house": 35,
                "rooms": 85,
                "beds": 155
            },
            "floors": [{
                    "floors_id": "b1-f1",
                    "floors_title": "Floor I",
                    "parent_id": "building_id",
                    "floor_stats": {
                        "house": 5,
                        "rooms": 20,
                        "beds": 40
                    },
                    "houses": [{
                            "house_id": "b1-f1-h1",
                            "house_name": "H1",
                            "house_photos": [],
                            "parent_id": "property_group_id",
                            "house_stats": {
                                "rooms": 4,
                                "beds": 7
                            },
                            "rooms": [{
                                    "room_id": "b1-f1-h1-r1",
                                    "room_no": "R1",
                                    "parent_id": "house_id",
                                    "room_photos": [],
                                    "room_stats": {
                                        "beds": 2
                                    },
                                    "beds": [{
                                            "bed_id": "b1-f1-h1-r1-b1",
                                            "bed_name": "B1"
                                        },
                                        {
                                            "bed_id": "b1-f1-h1-r1-b2",
                                            "bed_name": "B2"
                                        }]
                                },
                                {
                                    "room_id": "b1-f1-h1-r2",
                                    "room_name": "R2",
                                    "bed": []
                                }]
                        },
                        {
                            "house_id": "b1-f1-h2",
                            "house_name": "H2",
                            "room": []
                        }
                    ]
                },
                {
                    "floors_id": "b1-f2",
                    "floors_title": "Floor II",
                    "parent_id": "building_id",
                    "floor_stats": {
                        "house": 5,
                        "rooms": 20,
                        "beds": 40
                    },
                    "houses": [{
                            "house_id": "b1-f2-h1",
                            "house_name": "H1",
                            "house_photos": [],
                            "parent_id": "property_group_id",
                            "house_stats": {
                                "rooms": 4,
                                "beds": 7
                            },
                            "rooms": [{
                                    "room_id": "b1-f2-h1-r1",
                                    "room_no": "R1",
                                    "parent_id": "house_id",
                                    "room_photos": [],
                                    "room_stats": {
                                        "beds": 2
                                    },
                                    "beds": [{
                                            "bed_id": "b1-f2-h1-r1-b1",
                                            "bed_name": "B1"
                                        },
                                        {
                                            "bed_id": "b1-f2-h1-r1-b2",
                                            "bed_name": "B2"
                                        }]
                                },
                                {
                                    "room_id": "b1-f2-h1-r2",
                                    "room_name": "R2",
                                    "bed": []
                                }]
                        },
                        {
                            "house_id": "b1-f2-h2",
                            "house_name": "H2",
                            "room": []
                        }
                    ]
                }
            ]
        },
        {
            "building_id": "b002",
            "building_title": "B2",
            "building_project": "Shanders Properties",
            "building_address": "Beside Airport, Gokul Road ",
            "building_stats": {
                "floors": 5,
                "house": 33,
                "rooms": 75,
                "beds": 145
            },
            "floors": [{
                    "floors_id": "b2-f1",
                    "floors_title": "Floor I",
                    "parent_id": "building_id",
                    "floor_stats": {
                        "house": 5,
                        "rooms": 20,
                        "beds": 40
                    },
                    "houses": [{
                            "house_id": "b2-f1-h1",
                            "house_name": "H1",
                            "house_photos": [],
                            "parent_id": "property_group_id",
                            "house_stats": {
                                "rooms": 4,
                                "beds": 7
                            },
                            "rooms": [{
                                    "room_id": "b2-f1-h1-r1",
                                    "room_no": "R1",
                                    "parent_id": "house_id",
                                    "room_photos": [],
                                    "room_stats": {
                                        "beds": 2
                                    },
                                    "beds": [{
                                            "bed_id": "b2-f1-h1-r1-b1",
                                            "bed_name": "B1"
                                        },
                                        {
                                            "bed_id": "b2-f1-h1-r1-b2",
                                            "bed_name": "B2"
                                        }]
                                },
                                {
                                    "room_id": "b2-f1-h1-r2",
                                    "room_name": "R2",
                                    "bed": []
                                }]
                        },
                        {
                            "house_id": "b2-f1-h2",
                            "house_name": "H2",
                            "room": []
                        }
                    ]
                },
                {
                    "floors_id": "b2-f2",
                    "floors_title": "Floor II",
                    "parent_id": "building_id",
                    "floor_stats": {
                        "house": 5,
                        "rooms": 20,
                        "beds": 40
                    },
                    "houses": [{
                            "house_id": "b2-f2-h1",
                            "house_name": "H1",
                            "house_photos": [],
                            "parent_id": "property_group_id",
                            "house_stats": {
                                "rooms": 4,
                                "beds": 7
                            },
                            "rooms": [{
                                    "room_id": "b2-f2-h1-r1",
                                    "room_no": "R1",
                                    "parent_id": "house_id",
                                    "room_photos": [],
                                    "room_stats": {
                                        "beds": 2
                                    },
                                    "beds": [{
                                            "bed_id": "b2-f2-h1-r1-b1",
                                            "bed_name": "B1"
                                        },
                                        {
                                            "bed_id": "b2-f2-h1-r1-b2",
                                            "bed_name": "B2"
                                        }]
                                },
                                {
                                    "room_id": "b2-f2-h1-r2",
                                    "room_name": "R2",
                                    "bed": []
                                }]
                        },
                        {
                            "house_id": "b2-f2-h2",
                            "house_name": "H2",
                            "room": []
                        }
                    ]
                }

            ]
        }
    ]
}

1 个答案:

答案 0 :(得分:0)

我希望你能在@mwisnicki编辑后应用循环。 任何适当的JSON结构尝试http://jsonviewer.stack.hu/ 在这里,您可以查看JSON数据。

对于Array Object [],检查长度和循环限制为[] legnth。 对于{},使用其名称

直接获取该对象的值