java - 获取 JSON 对象的特定对象(XML 类型)
问题描述
<app:service xmlns:app="http://www.w3.org/2007/app"...>
<app:workspace>
<atom:title type="text">Data</atom:title>
<app:collection . . .>
<atom:title type="text">CourseContentSet</atom:title>
<demo:member-title>CourseContent</demo:member-title>
</app:collection>
<app:collection . . .>
<atom:title type="text">UnitContentSet</atom:title>
<demo:member-title>UnitContent</demo:member-title>
</app:collection>
</app:workspace>
</app:service>
我怎样才能得到演示:会员头衔?
我试过这样做但没有成功......
soapDatainJsonObject = XML.toJSONObject(soapmessageString);
JSONObjectsongs=soapDatainJsonObject.getJSONObject("app:service");
JSONObject songs2 = songs.getJSONObject("app:workspace");
String content = songs2.getString("app:collection")
System.out.println(content);
如何访问 XML 文件的内部部分?通过 JSON。我想获取 CourseContent、UnitContent.. 等
解决方案
您需要解析每个深度。试试这个:
JSONObject soapDatainJsonObject = XML.toJSONObject(soapmessageString);
JSONObject songs= soapDatainJsonObject.getJSONObject("app:service");
JSONObject songs2 = songs.getJSONObject("app:workspace");
JSONArray atomArray = songs2.getJSONArray("app:collection");
JSONObject atomTitle = atomArray.getJSONObject(0).getJSONObject("atom:title");
String content = atomTitle.getString("content");
System.out.println(content);
推荐阅读
- git - 如何将主分支合并到功能分支
- javascript - 鼠标位置上的水平滚动(鼠标填充)
- python - 将 DOCX 中的内容提取到 Python 代码中
- angular - Angular2 Http请求将baseURL添加到POST请求
- flash-cs6 - 导出 swf 文件 Flash CS6
- memory-management - 如何初始化具有固定大小数组的结构作为成员元素?
- php - 绑定从视图提交到控制器的值
- java - 从 java 8 流中获取 N(3) 个列表(基于 ENUM 性别(男性、女性、其他))并基于 ENUM 过滤条件
- java - 如何降低此 O(n^3) 代码的时间复杂度
- python - 如何比较具有相同列但顺序不同(SQL 或 python)的两个表?