2017-01-22 8 views
0

JSON을 반환하는 일부 날씨 API에서 데이터를 가져 오려고합니다. 목록의 모든 항목은 "레이블"이없는 노드로 간주되지만 여기에는 목록 안에 두 개의 노드가 들어 있습니다. root.get<string>("weather.description")Node does not exist 오류가 발생했기 때문에 description 라벨에 어떻게 액세스합니까?Boost :: ptree - 목록에 포함 된 속성 트리 노드에 액세스

for (auto it: root.get_child("weather")) { 
    cout << it.first.data() << "+"; 
    cout << it.second.data() << endl; 
} 

weather.json : (아무 것도 반환하지 않음) 내가을 시도 무엇

{ 
    "weather": [ 
     { 
      "id": "701", 
      "main": "Mist", 
      "description": "brume", 
      "icon": "50n" 
     }, 
     { 
      "id": "502", 
      "main": "Sun", 
      "description": "soleil", 
      "icon": "50b" 
     } 
    ] 
} 

답변

0

이에 대한 해결 방법을 찾을! 나는 날씨가 8 개의 분리 된 노드의 목록이라고 생각했지만 실제로 날씨의 두 자녀입니다. 이 방법은, 나는 다음과 같은 자신의 개인 데이터에 액세스 할 수 있습니다

for (auto it: root.get_child("weather")) { 
    cout << it.second.get_child("description").data() << endl; 
} 

반환 :

brume 
soleil