从HTML获取数据并将其转换为JSON [英] Get data from HTML and convert it to JSON

查看:4079
本文介绍了从HTML获取数据并将其转换为JSON的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的HTML输出:

 < input type ='text'id ='status'name ='status'value ='0'> 
< input type ='text'id ='description'name ='description'value ='Success'>
< input type ='text'id ='COMPANY'name ='COMPANY'value ='201'>

等等。



我会喜欢从中提取id,name和value,并将它们转换为java中的JSON。



编辑:我的JSPN输出看起来像

  {id:status,name:status,value:0} 

等。

解决方案

只需三步

1.创建一个html输入元素模型,它具有3个属性:id,name,value。

2.从html文件中提取值,可以使用htmlparser并使用这些值创建模型实例。



3.将模型实例转换为json字符串。

I have an output of HTML like this:

<input type='text' id='status' name='status' value='0'>
<input type='text' id='description' name='description' value='Success'>
<input type='text' id='COMPANY' name='COMPANY' value='201'>

and so on.

I would like to extract the id,name and value from this and convert them to JSON in java.

Edit: My JSPN output will look like

{"id": "status","name": "status", "value": "0"}

etc.

解决方案

just three steps

1.create a html Input element model which havs 3 properties: id,name,value.

2.extract values from the html file, you can use htmlparser and create a model instance using those values

3.convert model instance into json string.

这篇关于从HTML获取数据并将其转换为JSON的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆