2017-10-27 10 views
0

다음 json snip 및 im은 block_device_mapping 배열에서 boot_index의 마지막 인스턴스 값을 가져 오려고합니다. block_device_mapping 속성 만 표시되도록 설정할 수 있지만 자식 개체를 표시하는 데 어려움을 겪고 있습니다.JSON 경로 쿼리 배열 객체

{ "상태": "활성" "image_location": "스냅 샷" "block_device_mapping": "[{\"guest_format의 \ "널 \"boot_index \ "0 \"no_device \ "image_id \": null, \ "volume_id \": \ "eb7cf04e-c671-449d-ac1a-xxxxxxxxxx \", \ "device_name \": null, \ "disk_bus \": null, \ " \ "device_type \": \ "disk \", \ "snapshot_id \": null, \ "destination_type", "volume_size \": null, \ "source_type \ \ "guest_format \": null, \ "boot_index \": 1, \ "no_device \": null, \ "image_id \": null : \ "볼륨 \", \ "delete_on_termination \ \ "disk_bus \": null, \ "volume_size \": null, \ "source_type \": \ "volume_id \": \ "volume_id \": \ "2_31d59a-d005-4bdd-9921-xxxxxxxxx \ : null, \ "device_type \": \ "disk \", \ "snapshot_id \": null, \ "destination_type \": \ "volume \ ","delete_on_termination ": true}, {\"guest_format \ ": null, \"boot_index \ ": 2, \"no_device \ ": null, \"image_id \ ": null, \"volume_id \ \ "disk_bus \": null, \ "volume_size \": null, \ "source_type \": \ "볼륨 \", \ "disk_bus \", \ "volume_size \": \ "6cbc94dd- \ "태그 \": \ "device_type \": \ "디스크 \", \ "snapshot_id \": null, \ "대상 유형 \": \ "볼륨 \", \ "delete_on_termination \": , "visibility": "private" }

누구나 아이디어가 있습니까?

감사

R은

+0

그 json에 붙어 있습니까? "block_device_mapping"은 하나의 긴 문자열이므로 "잘 정의되어 있지는 않지만"구조가 잘되어 있지 않습니다. "[{.... ...., {...}, {...}]"의도 한 바가 아닐 것입니다. 따옴표 밖에있는 모든 백 슬래시. 나는 내 대답에 당신의 아들을 재구성했다. – Mark

답변

0

의견 위를 참조하십시오.

{ "상태": "활성" "image_location", "block_device_mapping"를 "스냅 샷"[ { "guest_format을"NULL, "boot_index를"0 "no_device를" 널 (null), "image_id"널 (null), "volume_id": "eb7cf04e-c671-449d-ac1a-XXXXXXXXXX", 'DEVICE_NAME "널 (null), "disk_bus "널 (null), "volume_size "널 (null), "SOURCE_TYPE ":"volume ", "tag ": null, "device_type ":"disk ", "snapshot_id ": null, "destination_type": "볼륨", "delete_on_termination"사실 }, { "guest_format"널 (null), "boot_index": 1, "no_device"널 (null), "image_id"널 (null), " volume_id ":"2e31d59a-d005-4bdd-9921-XXXXXXXXX ", 'DEVICE_NAME"널 (null), "disk_bus"널 (null), "volume_size"널 (null), "SOURCE_TYPE": "볼륨", "태그" null, "device_type": "disk", "snapshot_id": null, "destination_type": "볼륨", "delete_on_termination": true } { "guest_format"NULL, "boot_index"2 "no_device"NULL, "image_id"NULL, "volume_id": "6cbc94dd-bd1f-4845-a528-XXXXXXXXXX" 'DEVICE_NAME "널 (null), "disk_bus "널 (null), "volume_size "널 (null), "SOURCE_TYPE ":"볼륨 ", "태그 "널 (null), "DEVICE_TYPE ":"디스크 ", "snapshot_id " : null, "destination_type": "볼륨", "delete_on_termination": true } ], "visibility": "private" }

위의 내용을 변경하면 json이 훨씬 유용하다는 점에 유의하십시오. 복사하여 an online json viewer/editor과 같은 것으로 붙여 넣으십시오. 위의 코멘트에서 "block_device_mapping"은 "[{.... ...., {...},"...]와 같이 하나의 긴 문자열 이었으므로 json-like 또는 도움이되지는 않습니다.

"block_device_mapping"변경 사항은 이제 세 개의 개별 객체로 구성됩니다.

someRootObject.block_device_mapping [2] .boot_index를 통해 마지막 "boot_index"를 얻을 수 있습니다. "someRootObject"는 코드에서이 전체 json 객체를 호출하는 모든 것이됩니다.