편집 기록

편집 기록
  • 프로필 이야이야님의 편집
    날짜2019.10.01

    파이썬 json 특정값 추출


    {
        "test": [
            {
                "customer": "test1",
                "type": [
                    "windows"
                ],
                "contact": [{
                    "name": "a",
                    "email": "@gmail.com",
                    "phone": null ,
                    "remarks": null
                }]
            },
            {
                "customer": "test2",
                "type": [
                    "android"
                ],
                "contact": [{
                    "name": "b",
                    "email": "@gmail.com",
                    "phone": "010-0000-0000",
                    "remarks": null
                }]
            },
            {
                "customer": "test3",
                "type": [
                    "android"
                ],
                "contact": [{
                    "name": "a",
                    "email": "@naver.com",
                    "phone": null,
                    "remarks": null
                }]
            }
        ]
    }
    
    import json
    
    with open('test.json', 'rt', encoding='UTF8') as f:
        content = json.load(f)
    email_list = [ x for x in content['omnidoc']['contact']['email'].keys()]
    

    파이썬에서 json파일의 email데이터만 리스트로 가져오고 싶은데 어떻게 해야할까요? 그리고 중복제거까지 하고싶어요.

    여기서는 이런 오류가 나오네요.

    TypeError: list indices must be integers or slices, not str
    
  • 프로필 nowp님의 편집
    날짜2019.10.01

    파이썬 json 특정값 추출


    {
        "test": [
            {
                "customer": "test1",
                "type": [
                    "windows"
                ],
                "contact": [{
                    "name": "a",
                    "email": "@gmail.com",
                    "phone": null ,
                    "remarks": null
                }]
            },
            {
                "customer": "test2",
                "type": [
                    "android"
                ],
                "contact": [{
                    "name": "b",
                    "email": "@gmail.com",
                    "phone": "010-4212-8468",
                    "remarks": null
                }]
            },
            {
                "customer": "test3",
                "type": [
                    "android"
                ],
                "contact": [{
                    "name": "a",
                    "email": "@naver.com",
                    "phone": null,
                    "remarks": null
                }]
            }
        ]
    }
    
    import json
    
    with open('test.json', 'rt', encoding='UTF8') as f:
        content = json.load(f)
    email_list = [ x for x in content['omnidoc']['contact']['email'].keys()]
    

    파이썬에서 json파일의 email데이터만 리스트로 가져오고 싶은데 어떻게 해야할까요? 그리고 중복제거까지 하고싶어요.

    여기서는 이런 오류가 나오네요.

    TypeError: list indices must be integers or slices, not str
    
  • 프로필 이야이야님의 편집
    날짜2019.10.01

    파이썬 json 특정값 추출


    {
        "test": [
            {
                "customer": "test1",
                "type": [
                    "windows"
                ],
                "contact": [{
                    "name": "a",
                    "email": "@gmail.com",
                    "phone": null ,
                    "remarks": null
                }]
            },
            {
                "customer": "test2",
                "type": [
                    "android"
                ],
                "contact": [{
                    "name": "b",
                    "email": "@gmail.com",
                    "phone": "010-4212-8468",
                    "remarks": null
                }]
            },
            {
                "customer": "test3",
                "type": [
                    "android"
                ],
                "contact": [{
                    "name": "a",
                    "email": "@naver.com",
                    "phone": null,
                    "remarks": null
                }]
            }
        ]
    }
    
    import json
    
    with open('test.json', 'rt', encoding='UTF8') as f:
        content = json.load(f)
    email_list = [ x for x in content['omnidoc']['contact']['email'].keys()]
    

    파이썬에서 json파일의 email데이터만 리스트로 가져오고 싶은데 어떻게 해야할까요? 그리고 중복제거까지 하고싶어요 여기서는 이런 오류가 나오네요ㅜㅜ TypeError: list indices must be integers or slices, not str