2014-06-16 67 views
-2

我有以下的JSON響應如何使用JSON路徑解析器遍歷JSON?

'{ "person_list": 
[ 

    { 
"id": "4", 
"demographics": { 
    "address": { 
    "city": "Tokyo", 
    "country": "Japan", 
    "county_or_parish": "some county", 
    "postal_code": "98765", 
    "state_or_province": "some state", 
    "street_addresses": [ 
     "123 Some Street" 
    ] 
    }, 
    "date_of_birth": "1964-01-30T00:00:00.000Z", 
    "date_of_death": "2013-01-30T00:00:00.000Z", 
    "deceased": true, 
    "emails": [], 
    "gender": "Male", 
    "full_name": "Yagami Light M", 
    "given_names": [ 
    "Light", 
    "Maes" 
    ], 
    "family_names": [ 
    "Yagami", 
    "Hughes" 
    ], 
    "prefix": "Dr.", 
    "suffix": "Jr.", 
    "telecoms": [], 
    "mrn_aliases": [], 
    "payer_info": [], 
    "person_benefit_coverages": [] 
}, 
"mara_risk_scores": [ 
    { 
    "score": 10.0, 
    "model": "CXCONLAG0" 
    }, 
    { 
    "score": 20.0, 
    "model": "CXCONLAG1" 
    }, 
    { 
    "score": 30.0, 
    "model": "CXCONLAG2" 
    } 
    ], 
    "dashboard": {}, 
    "has_flagged_manual_data": true, 
    "record_ids": [] 
}, 
    { 
    "id": "3", 
    "demographics": { 
    "emails": [], 
    "given_names": [], 
    "family_names": [], 
    "telecoms": [], 
    "mrn_aliases": [], 
    "payer_info": [], 
    "person_benefit_coverages": [] 
    }, 
    "mara_risk_scores": [], 
    "dashboard": {}, 
    "has_flagged_manual_data": false, 
    "record_ids": [] 
    } 
    ] 
    }' 

現在我想要得到的ID是等於我從另一個對象中檢索到的empi_id的人口統計..

我想這個.. JsonPath .read(jsonObject,「$。person_list []。demographics」,filter(where(「id」)。eq(cs.getEmpiId())))

它似乎不工作..你能幫我接着就,隨即?

回答

1

這JSONPath表達應該可以幫助你得到你所需要的東西:

$.person_list[?(@.id=='4')].demographics 

更換4你感興趣的人的ID,它應該做的伎倆。