如何显示从Json检索的数据并根据来自json的html标签显示它

时间:2017-01-12 16:01:55

标签: android json

我想以表格格式显示数据,这是我的JSON响应,

  [{
    "description": "<p>Payment Condition : Same Day</p>\r\n<table>\r\n    <tbody>\r\n        <tr>\r\n            <th>Thickness</th>\r\n            <th>Edge</th>\r\n            <th>Width</th>\r\n            <th>Finish</th>\r\n            <th>Quantity about</th>\r\n            <th>Rate</th>\r\n        </tr>\r\n        <tr>\r\n            <td>0.3 mm</td>\r\n            <td>Mill edge</td>\r\n            <td>510mm</td>\r\n            <td>BA TWO SIDE</td>\r\n            <td>3 ton</td>\r\n            <td>131</td>\r\n        </tr>\r\n        <tr>\r\n            <td>0.3mm</td>\r\n            <td>Mill edge</td>\r\n            <td>510mm</td>\r\n            <td>BA TWO SIDE</td>\r\n            <td>100 kg</td>\r\n            <td>133</td>\r\n        </tr>\r\n        <tr>\r\n            <td>0.4mm</td>\r\n            <td>Mill edge</td>\r\n            <td>510mm</td>\r\n            <td>BA TWO SIDE</td>\r\n            <td>3 ton</td>\r\n            <td>129</td>\r\n        </tr>\r\n        <tr>\r\n            <td>0.4mm</td>\r\n            <td>Mill edge</td>\r\n            <td>510mm</td>\r\n            <td>BA TWO SIDE</td>\r\n            <td>100 kg</td>\r\n            <td>131</td>\r\n        </tr>\r\n        <tr>\r\n            <td>0.4mm</td>\r\n            <td>Mill edge</td>\r\n            <td>510mm</td>\r\n            <td>2B Finish</td>\r\n            <td>3 ton</td>\r\n            <td>125</td>\r\n        </tr>\r\n        <tr>\r\n            <td>0.5mm</td>\r\n            <td>Mill edge</td>\r\n            <td>510mm</td>\r\n            <td>BA TWO SIDE</td>\r\n            <td>3 ton</td>\r\n            <td>125</td>\r\n        </tr>\r\n        <tr>\r\n            <td>0.5mm</td>\r\n            <td>Mill edge</td>\r\n            <td>510mm</td>\r\n            <td>BA TWO SIDE</td>\r\n            <td>100 kg</td>\r\n            <td>127</td>\r\n        </tr>\r\n        <tr>\r\n            <td>0.5mm</td>\r\n            <td>Mill edge</td>\r\n            <td>510mm</td>\r\n            <td>2B Finish</td>\r\n            <td>3 ton</td>\r\n            <td>122</td>\r\n        </tr>\r\n        <tr>\r\n            <td>0.6mm</td>\r\n            <td>Mill edge</td>\r\n            <td>510/485mm</td>\r\n            <td>2B Finish</td>\r\n            <td>3 ton</td>\r\n            <td>120</td>\r\n        </tr>\r\n        <tr>\r\n            <td>0.7 to 1.5mm</td>\r\n            <td>Mill edge</td>\r\n            <td>510/485mm</td>\r\n            <td>2B Finish</td>\r\n            <td>3 ton</td>\r\n            <td>118</td>\r\n        </tr>\r\n        <tr>\r\n            <td>0.6 to 1.5mm</td>\r\n            <td>Slit edge</td>\r\n            <td>38 to 238mm</td>\r\n            <td>2B Finish</td>\r\n            <td>100 kg</td>\r\n            <td>122</td>\r\n        </tr>\r\n    </tbody>\r\n</table>",
    "error": false,
    "message": "RESULT_OK",
    "photo": "http://derk.jbsoftware.co.in/products/smallphoto/20c6ec1f-e858-41ac-9383-4a47e25a2939.jpg",
    "product_id": "1",
    "title": "S.S. 201 COIL"
  }]

在描述html标签表中,p,tr,td使用我想根据html标签显示数据,如果表标签比表创建并根据表格设置tr和td标签中的数据。

1 个答案:

答案 0 :(得分:0)

这是您的问题的解决方案。您必须Html.fromHtml(youstrinf)才能实现此目标。

  

txtViewdescrip.setText(Html.fromHtml(介绍));

通过使用此标记删除所有HTML标记,并以HTML格式格式化您的String