首页 新闻 会员 周边 捐助

json数据与html table表格之间的转换

0
悬赏园豆:20 [已关闭问题] 关闭于 2014-07-21 00:45

<table id="table" style="width: 100%;" cellpadding="0" cellspacing="0">
        <thead>
            <tr>
                <td>颜色</td>
                <td>套餐</td>
                <td>版本</td>
                <td>价格</td>
                <td>数量</td>
                <td>编号</td>
                <td>条形码</td>
            </tr>
        </thead>
        <tbody>
            <tr>
                <td rowspan="4">红色</td>
                <td rowspan="2">套餐四</td>
                <td>港货</td>
                <td>99.9</td>
                <td>100</td>
                <td>123456789</td>
                <td>987654321</td>
            </tr>
            <tr>
                <td>日货</td>
                <td>99.9</td>
                <td>100</td>
                <td>123456789</td>
                <td>987654321</td>
            </tr>
            <tr>
                <td rowspan="2">套餐八</td>
                <td>港货</td>
                <td>99.9</td>
                <td>100</td>
                <td>123456789</td>
                <td>987654321</td>
            </tr>
            <tr>
                <td>日货</td>
                <td>99.9</td>
                <td>100</td>
                <td>123456789</td>
                <td>987654321</td>
            </tr>
            <tr>
                <td rowspan="4">蓝色</td>
                <td rowspan="2">套餐四</td>
                <td>港货</td>
                <td>99.9</td>
                <td>100</td>
                <td>123456789</td>
                <td>987654321</td>
            </tr>
            <tr>
                <td>日货</td>
                <td>99.9</td>
                <td>100</td>
                <td>123456789</td>
                <td>987654321</td>
            </tr>
            <tr>
                <td rowspan="2">套餐八</td>
                <td>港货</td>
                <td>99.9</td>
                <td>100</td>
                <td>123456789</td>
                <td>987654321</td>
            </tr>
            <tr>
                <td>日货</td>
                <td>99.9</td>
                <td>100</td>
                <td>123456789</td>
                <td>987654321</td>
            </tr>
        </tbody>
    </table>

 

我这是一个html的表格,行列都是不确定的,上面数据只是一种例子。

用js怎么把此数据表格转化成一个json数据,并且也可以把json数据转化成这中表格,是双向的。应该如何实现呢。

json的格式我已经定义好了,不过中间的过程转化确实感觉不好实现,有哪位大神能帮忙解决一下啊。求一个读写转化的方法。

下面是json格式:

var _77 = {
    "Category": [
        "机身颜色",
        "套餐类型",
        "机身内存",
        "版本型号"
    ],
    "Series": [
        {
            "红": [
                {
                    "套餐四": [
                        {
                            "1.5GB": [
                                {
                                    "港澳台": [
                                        99.9,
                                        100,
                                        "4561545613",
                                        "123456789"
                                    ],
                                    "日本": [
                                        88.8,
                                        222,
                                        "9876453142",
                                        "654789313"
                                    ]
                                }
                            ],
                            "64GB以上": [
                                 {
                                     "港澳台": [
                                         99.9,
                                         100,
                                         "4561545613",
                                         "123456789"
                                     ],
                                     "日本": [
                                         88.8,
                                         222,
                                         "9876453142",
                                         "654789313"
                                     ]
                                 }
                            ]
                        }
                    ]
                },
                {
                    "套餐八": [
                        {
                            "1.5GB": [
                                {
                                    "港澳台": [
                                        99.9,
                                        100,
                                        "4561545613",
                                        "123456789"
                                    ],
                                    "日本": [
                                        88.8,
                                        222,
                                        "9876453142",
                                        "654789313"
                                    ]
                                }
                            ],
                            "64GB以上": [
                                {
                                    "港澳台": [
                                        99.9,
                                        100,
                                        "4561545613",
                                        "123456789"
                                    ],
                                    "日本": [
                                        88.8,
                                        222,
                                        "9876453142",
                                        "654789313"
                                    ]
                                }
                            ]
                        }
                    ]
                }
            ]
        },
        {
            "蓝": [
                {
                    "套餐四": [
                        {
                            "1.5GB": [
                                {
                                    "港澳台": [
                                        99.9,
                                        100,
                                        "4561545613",
                                        "123456789"
                                    ],
                                    "日本": [
                                        88.8,
                                        222,
                                        "9876453142",
                                        "654789313"
                                    ]
                                }
                            ],
                            "64GB以上": [
                                {
                                    "港澳台": [
                                        99.9,
                                        100,
                                        "4561545613",
                                        "123456789"
                                    ],
                                    "日本": [
                                        88.8,
                                        222,
                                        "9876453142",
                                        "654789313"
                                    ]
                                }
                            ]
                        }
                    ]
                },
                {
                    "套餐八": [
                        {
                            "1.5GB": [
                                {
                                    "港澳台": [
                                        99.9,
                                        100,
                                        "4561545613",
                                        "123456789"
                                    ],
                                    "日本": [
                                        88.8,
                                        222,
                                        "9876453142",
                                        "654789313"
                                    ]
                                }
                            ],
                            "64GB以上": [
                                {
                                    "港澳台": [
                                        99.9,
                                        100,
                                        "4561545613",
                                        "123456789"
                                    ],
                                    "日本": [
                                        88.8,
                                        222,
                                        "9876453142",
                                        "654789313"
                                    ]
                                }
                            ]
                        }
                    ]
                }
            ]
        }
    ]
}

 

 

老江湖的主页 老江湖 | 初学一级 | 园豆:104
提问于:2014-07-20 11:56
< >
分享
所有回答(1)
0

您好我想问一下您这个问题怎么解决的?比较着急,请速回复谢谢

 

太白水桶 | 园豆:195 (初学一级) | 2016-03-30 10:27
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册