JSONレスポンス今どのように私はジャクソンjsonNodeを使用してこれを達成し、所望の出力
{
"searchResults": {
"@xmlns": {
"dvi": "http://localhsot.com/ns/1.0",
"$": "http://localhsot.com/ns/1.0",
"a": "http://alternate.localhsot.com/ns/1.0"
},
"@totalCount": "2",
"file": [
{
"link": [
{
"@rel": "file",
"$": "file.url"
},
{
"@rel": "content",
"$": "content.url"
},
{
"@rel": "repository",
"$": "repository.url"
},
{
"@rel": "content.alternate",
"@a:width": "320",
"@a:height": "320",
"@a:imageFormat": "jpeg",
"@a:mimeType": "image/jpeg",
"@a:size": "-1",
"$": "some.url"
},
{
"@rel": "content.alternate",
"@a:width": "64",
"@a:height": "64",
"@a:imageFormat": "jpeg",
"@a:mimeType": "image/jpeg",
"@a:size": "-1",
"$": "some.url"
},
{
"@rel": "content.alternate",
"@a:width": "24",
"@a:height": "24",
"@a:imageFormat": "jpeg",
"@a:mimeType": "image/jpeg",
"@a:size": "-1",
"$": "some.url"
},
{
"@rel": "content.alternate",
"@a:width": "128",
"@a:height": "128",
"@a:imageFormat": "jpeg",
"@a:mimeType": "image/jpeg",
"@a:size": "-1",
"$": "some.url"
}
],
"name": {
"$": "gullfoss.jpg"
},
"parentPath": {
"$": "/"
},
"size": {
"$": "91345"
},
"versionCreated": {
"$": "2017-01-13T16:38:20.059Z"
},
"systemAttribute": [
{
"@name": "Geo-Latitude",
"$": "47.6065"
},
{
"@name": "Geo-Longitude",
"$": "22.99514"
},
{
"@name": "Height",
"$": "579"
},
{
"@name": "Mime-Type",
"$": "image/jpeg"
},
{
"@name": "Timeline-Date",
"$": "-0091-03-27T04:26:40.000Z"
},
{
"@name": "Width",
"$": "680"
}
],
"attributesChanged": {
"$": "false"
},
"deleted": {
"$": "false"
},
"repository": {
"$": "VZMOBILE_13psb6j"
},
"checksum": {
"$": "5d828c1d94b2569ff1bf60a9ebe9cd2de8ae8e6a9ad7d77d678c1766c78957c5"
},
"extension": {
"$": "jpg"
},
"fileAttribute": [
{
"@name": "ContentPermissions",
"$": "SHARE"
},
{
"@name": "Width",
"$": "680"
},
{
"@name": "CI_COMPLETE",
"$": "true"
},
{
"@name": "DRM_PROTECTED",
"$": "false"
},
{
"@name": "Height",
"$": "579"
}
],
"contentToken": {
"$": "AHYLsb1sK9iy1Rn3yS4mQiM5pFL--AyTjY3i5G-zzdOm68QzB_GILrt1pXgfdEkUcPZZ5tUpn1Ih3j9wyfywIVY~"
},
"contentAccessible": {
"$": "true"
},
"contentChanged": {
"$": "false"
}
},
{
"link": [
{
"@rel": "file",
"$": "file.url"
},
{
"@rel": "content",
"$": "content.url"
},
{
"@rel": "repository",
"$": "repository.url"
},
{
"@rel": "content.alternate",
"@a:width": "320",
"@a:height": "320",
"@a:imageFormat": "jpeg",
"@a:mimeType": "image/jpeg",
"@a:size": "-1",
"$": "some.url"
},
{
"@rel": "content.alternate",
"@a:width": "64",
"@a:height": "64",
"@a:imageFormat": "jpeg",
"@a:mimeType": "image/jpeg",
"@a:size": "-1",
"$": "some.url"
},
{
"@rel": "content.alternate",
"@a:width": "24",
"@a:height": "24",
"@a:imageFormat": "jpeg",
"@a:mimeType": "image/jpeg",
"@a:size": "-1",
"$": "some.url"
},
{
"@rel": "content.alternate",
"@a:width": "128",
"@a:height": "128",
"@a:imageFormat": "jpeg",
"@a:mimeType": "image/jpeg",
"@a:size": "-1",
"$": "some.url"
}
],
"name": {
"$": "gullfoss.jpg"
},
"parentPath": {
"$": "/Folder"
},
"size": {
"$": "91345"
},
"versionCreated": {
"$": "2017-01-13T16:38:59.728Z"
},
"systemAttribute": [
{
"@name": "Geo-Latitude",
"$": "47.6065"
},
{
"@name": "Geo-Longitude",
"$": "22.99514"
},
{
"@name": "Height",
"$": "579"
},
{
"@name": "Mime-Type",
"$": "image/jpeg"
},
{
"@name": "Timeline-Date",
"$": "-0091-03-27T04:26:40.000Z"
},
{
"@name": "Width",
"$": "680"
}
],
"attributesChanged": {
"$": "false"
},
"deleted": {
"$": "false"
},
"repository": {
"$": "VZMOBILE_13psb6j"
},
"checksum": {
"$": "5d828c1d94b2569ff1bf60a9ebe9cd2de8ae8e6a9ad7d77d678c1766c78957c5"
},
"extension": {
"$": "jpg"
},
"fileAttribute": [
{
"@name": "ContentPermissions",
"$": "SHARE"
},
{
"@name": "Width",
"$": "680"
},
{
"@name": "CI_COMPLETE",
"$": "true"
},
{
"@name": "DRM_PROTECTED",
"$": "false"
},
{
"@name": "Height",
"$": "579"
}
],
"contentToken": {
"$": "AHYLsb1sK9iy1Rn3yS4mQiM5pFL--AyTjY3i5G-zzdOm68QzB_GILrt1pXgfdEkUcPZZ5tUpn1Ih3j9wyfywIVY~"
},
"contentAccessible": {
"$": "true"
},
"contentChanged": {
"$": "false"
}
}
]
}
}
を得ることができ、私はつまり、このJSONレスポンスをtravesingことにより、2つの状態を確認したい、まず上記のJSON文字列から@totalCountを取得
第二の条件は、各ファイルノードをループと参照
(myrepoName.equals(JSONレスポンスリポジトリ名) 、リンクノードからリポジトリのコンテンツのURLを取得する場合。この
あります{
"@rel": "content",
"$": "content.url" <---
}
マイコード:すべての
try {
JsonNode jsonNode = new ObjectMapper().readTree(response.prettyPrint());
int totalCount = jsonNode.at("/searchResults/@totalCount").asInt();
logger.info("Search returned " + totalCount + " results");
if(totalCount > 0) {
JsonNode filesNode = jsonNode.at("/searchResults/file");
logger.info("Result: " + filesNode);
if(filesNode.isObject()) {
Iterator<JsonNode> filesIterator = filesNode.elements();
while (filesIterator.hasNext())
{
// what i'm trying to get here is this
JsonNode fileNode = filesIterator.next();
Object name = fileNode.at("/$").asText();
if (repoName.equals(name)) {
logger.info("Got it");
//get the content URL from link node
//missing code
logger.info("Returning " + contentURL + " for repo " + repoName);
break;
}
}
}
}
} catch (IOException e) {
e.printStackTrace();
}
ありがとうございます。あなたは私の一日を作ったばかりです。 –
@SyedShareefAhmed私の喜びはあなたを助けることです。ハッピーコーディングと素敵な一日を! –