파이썬에서 json 가져 오기

코드 예제

53
0

파이썬 읽기 json 파일

import json

with open('path_to_file/person.json') as f:
  data = json.load(f)

print(data)
1
0

파이썬 가져 오기 json 데이터

# Basic syntax:
import ast
# Create function to import JSON-formatted data:
def import_json(filename):
  for line in open(filename):
    yield ast.literal_eval(line)
# Where ast.literal_eval allows you to safely evaluate the json data.
# 	See the following link for more on this:
# 	https://stackoverflow.com/questions/15197673/using-pythons-eval-vs-ast-literal-eval
        
# Import json data
data = list(import_json("/path/to/filename.json"))

# (Optional) convert json data to pandas dataframe:
dataframe = pd.DataFrame.from_dict(data)
# Where keys become column names
1
0

파이썬을 사용하여 json 에서 특정 데이터를 얻는 방법

with open('distros.json', 'r') as f:
    distros_dict = json.load(f)

for distro in distros_dict:
    print(distro['Name'])

다른 언어로

이 페이지는 다른 언어로되어 있습니다

Русский
..................................................................................................................
English
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
中文
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................
Балгарскі
..................................................................................................................
Íslensk
..................................................................................................................