image.png
    image.png
    image.png

    示例代码1

    1. data = {
    2. "store": {
    3. "book": [
    4. {
    5. "category": "reference",
    6. "author": "Nigel Rees",
    7. "title": "Sayings of the Century",
    8. "price": 8.95
    9. },
    10. {
    11. "category": "fiction",
    12. "author": "Evelyn Waugh",
    13. "title": "Sword of Honour",
    14. "price": 12.99
    15. },
    16. {
    17. "category": "fiction",
    18. "author": "Herman Melville",
    19. "title": "Moby Dick",
    20. "isbn": "0-553-21311-3",
    21. "price": 8.99
    22. },
    23. {
    24. "category": "fiction",
    25. "author": "J. R. R. Tolkien",
    26. "title": "The Lord of the Rings",
    27. "isbn": "0-395-19395-8",
    28. "price": 22.99
    29. }
    30. ],
    31. "bicycle": {
    32. "color": "red",
    33. "price": 19.95
    34. }
    35. },
    36. "expensive": 10
    37. }
    38. if __name__ == '__main__':
    39. print(data)
    40. # search = '$.store.*'
    41. search = '$.expensive.'
    42. node = jsonpath.jsonpath(data, search)
    43. print(node)

    示例代码2

    1. import jsonpath
    2. jsonobj ={
    3. "state":1,
    4. "message":"success",
    5. "content":{
    6. "data":{
    7. "allCitySearchLabels":{
    8. "A":[{"id":105795,"name":"澳门特别行政区"},
    9. {"id":671,"name":"安庆"},
    10. {"id":601,"name":"鞍山"}
    11. ]
    12. }
    13. }
    14. }
    15. }
    16. # 从根节点开始,匹配name节点