smart-fun / XmlToJson

Android Library for converting XML to JSON and JSON to XML
Apache License 2.0
557 stars 112 forks source link

xml to json error name; #3

Closed lcw1987565 closed 7 years ago

lcw1987565 commented 7 years ago

I have found a problem: xml = `<?xml version="1.0" encoding="gb2312"?>

用户名 1 周玉英 1 userName text 联系电话 1 1 userPhone text 设备号 1 AD0001595170 1 dealCode text 工作时间 1 1 workTime datetime 工作大类 1 1 workType select repair 故障修理 结案原因 1 1 faultCause tree 01-01 电缆修复 0057381 01 01-03 电缆开头子修复 0057381 01 01-07 电缆公务 0057381 01 1 成功

`

XmlToJson xmlToJson = new XmlToJson.Builder(xmlString) .forceList("/root/data/responsedata/entity/PARAM_DICT/entity") .forceList("/root/data/responsedata/entity") .build(); String jsonStr = xmlToJson.toJson().toString();

will i get the result is:

the "rowNum" should be “entity”; { "PARAM_DICT": { "rowNum": [{ "ID": "repair", "rowNum": 0, "NAME": "故障修理" }] }, "PARAM_TYPE": 1, "HTML_TYPE": "select", "PARAM_CODE": "workType", "PARAM": "工作大类", "rowNum": 4, "TYPE": 1 }

full json: { "root": { "data": { "responsedata": { "result": 1, "result_info": "成功", "entity": [{ "PARAM_TYPE": 1, "HTML_TYPE": "text", "PARAM_CODE": "userName", "PARAM": "用户名", "PARAM_VALUE": "周玉英", "rowNum": 0, "TYPE": 1 }, { "PARAM_TYPE": 1, "HTML_TYPE": "text", "PARAM_CODE": "userPhone", "PARAM": "联系电话", "rowNum": 1, "TYPE": 1 }, { "PARAM_TYPE": 1, "HTML_TYPE": "text", "PARAM_CODE": "dealCode", "PARAM": "设备号", "PARAM_VALUE": "AD0001595170", "rowNum": 2, "TYPE": 1 }, { "PARAM_TYPE": 1, "HTML_TYPE": "datetime", "PARAM_CODE": "workTime", "PARAM": "工作时间", "rowNum": 3, "TYPE": 1 }, { "PARAM_DICT": { "rowNum": [{ "ID": "repair", "rowNum": 0, "NAME": "故障修理" }] }, "PARAM_TYPE": 1, "HTML_TYPE": "select", "PARAM_CODE": "workType", "PARAM": "工作大类", "rowNum": 4, "TYPE": 1 }, { "PARAM_DICT": { "rowNum": 3, "entity": [{ "ID": "01-01", "SPECIALTYID": 57381, "NAME": "电缆修复", "rowNum": 0, "GROUPID": 1 }, { "ID": "01-03", "SPECIALTYID": 57381, "NAME": "电缆开头子修复", "rowNum": 1, "GROUPID": 1 }, { "ID": "01-07", "SPECIALTYID": 57381, "NAME": "电缆公务", "rowNum": 2, "GROUPID": 1 }] }, "PARAM_TYPE": 1, "HTML_TYPE": "tree", "PARAM_CODE": "faultCause", "PARAM": "结案原因", "rowNum": 5, "TYPE": 1 }] } } } }

smart-fun commented 7 years ago

Hello!

thanks for reporting this issue, I'm looking into it right now.

I'm sorry for this bug, I tell you when I have a fix for it.

Arnaud.

smart-fun commented 7 years ago

Hi,

sorry for the delay, I was quite busy these days. I have made a fix and published it (version 1.2.2). All my unit tests pass so it should be ok. Please tell me if this fixes your problem (I'm sure it will ^^) so that I will close this issue.

thanks again for reporting,

Arnaud.

smart-fun commented 7 years ago

Hello,

I close this ticket as it is supposed to be fixed with the latest release.

Arnaud.