【发布时间】:2014-11-05 16:03:16
【问题描述】:
我的 xml 在某些节点中包含一些 html 内容,例如
<detail>
<P>Students should avoid purchasing their textbooks at the first store that they browse. Instead, they should investigate the alternatives offered by other online booksellers. Price isn't the only factor to consider when making an online purchase. Students should also factor in shipping costs and delivery time when making their buying decision.</P>
</detail>
通过 json 或 json-lib 将 xml 转换为 Json 时,通过
import net.sf.json.JSON;
import net.sf.json.xml.XMLSerializer;
.....
JSONObject jsonObject = XML.toJSONObject(xml.toString());
......
xml 是包含 xml 内容的字符串
我应该得到 json 字符串为
{"detail":"<P>Students should avoid purchasing their textbooks at the first store that they browse. Instead, they should investigate the alternatives offered by other online booksellers. Price isn't the only factor to consider when making an online purchase. Students should also factor in shipping costs and delivery time when making their buying decision.</P>"}
但输出类似于
{"detail":{"P":"Students should avoid purchasing their textbooks at the first store that they browse. Instead, they should investigate the alternatives offered by other online booksellers. Price isn't the only factor to consider when making an online purchase. Students should also factor in shipping costs and delivery time when making their buying decision."}}
这是不对的。
谁能告诉我如何解决这个问题?
【问题讨论】:
-
您使用什么语言? php、java、javascript、C++、C#、BASIC?您用来进行转换的代码在哪里?
-
语言是 java:
import org.json.JSONObject; import org.json.XML;JSONObject jsonObject = XML.toJSONObject(xml);xml 是包含 xml 内容的字符串。 -
您应该用 java 标记您的问题,而不是让其他人知道您使用的是什么语言,并且您将代码放在问题中而不是 cmets。