【问题标题】:Getting specific object of JSON object(XML type)获取 JSON 对象的特定对象(XML 类型)
【发布时间】:2018-07-23 08:19:06
【问题描述】:
<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..等

【问题讨论】:

    标签: java json xml eclipse


    【解决方案1】:

    您需要解析每个深度。试试这个:

    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);
    

    【讨论】:

      猜你喜欢
      • 2013-01-20
      • 2022-08-15
      • 1970-01-01
      • 1970-01-01
      • 2017-07-03
      • 2017-11-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多