0

org.json.JSONObject ライブラリを使用して json 応答から特定のデータを抽出しようとしています。ここに私の json 応答があります。

{
"facets": {
"application": [
  {
    "name": "38",
    "distribution": 1
  }
],
"node": [
  {
    "name": "frstlwardu03_05",
    "distribution": 1
  }
],
"area": [
  {
    "name": "x",
    "distribution": 1
  }
],
"company": [
  {
    "name": "war001",
    "distribution": 1
  }
]
},
"duObjects": [
 {
  "id": "TASK|TSK(ZRM760J)(000)(ZRM760JU00)(000)|ZSRPSRM000",
  "name": "TSK(ZRM760J)(000)(ZRM760JU00)(000)",
  "mu": "ZSRPSRM000",
  "label": "",
  "session": "ZRM760J|000",
  "sessionLabel": "SAP SRM Achats frais generaux execution",
  "uprocHeader": "ZRM760JU00|000",
  "uprocHeaderLabel": "Header for SRM760J",
  "uprocHeaderType": "CL_INT",
  "domain": "M",
  "domainLabel": "",
  "application": "38",
  "applicationLabel": "magasin",
  "highlightResult": {
    "name": "name",
    "word": "TSK"
  }
}
],
"totalCount": 1,
"pageSize": 10,
"pageCurrent": 1,
"pageNb": 1
}

URL 呼び出しを jsonobject に変換するために使用した方法は次のとおりです。

public static JSONObject readJsonFromUrl(String url) throws IOException, JSONException    
{    
InputStream is = new URL(url).openStream();
try {
BufferedReader rd = new BufferedReader(new InputStreamReader(is, Charset.forName("UTF-     
8")));
  String jsonText = readAll(rd);
  JSONObject json = new JSONObject(jsonText);
  return json;
} finally {
  is.close();
}
}

このメソッドを呼び出すと、 Duobject でデータを取得できます。

public static void main(String[] args) throws IOException, JSONException {
JSONObject json = readJsonFromUrl("http://frstmwarwebsrv.orsyptst.com:9000/duobject?      
searchString=TSK(ZRM760J)(000)(ZRM760JU00)
(000)&filterchecks=nameJob,nameWF,nameSWF,application,domain&p.index=0&p.size=10");
System.out.println(json.getJSONArray("duObjects"));


} 

とにかく、DuObjects の名前フィールドのみを抽出できますか?

4

3 に答える 3