Python:解析json列表
大家好,我基本上想解析这个json数据Python:解析json列表,json,Json,大家好,我基本上想解析这个json数据 [ { "id": 417862, "name": "octokit.rb", "full_name": "octokit/octokit.rb", "owner": { "login": "octokit", "id": 3430433, "avatar_url": "https://avatars0.githu
[
{
"id": 417862,
"name": "octokit.rb",
"full_name": "octokit/octokit.rb",
"owner": {
"login": "octokit",
"id": 3430433,
"avatar_url": "https://avatars0.githubusercontent.com/u/3430433?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/octokit",
"html_url": "https://github.com/octokit",
"followers_url": "https://api.github.com/users/octokit/followers",
"following_url": "https://api.github.com/users/octokit/following{/other_user}",
"gists_url": "https://api.github.com/users/octokit/gists{/gist_id}",
"starred_url": "https://api.github.com/users/octokit/starred{/owner}{/repo}",
"subscriptions_url":
} ]
我的问题是如何从json获取“id”:417862
的值
谢谢。那么:
mylist = [{
"id": 417862,
"name": "octokit.rb",
"full_name": "octokit/octokit.rb",
"owner": {
"login": "octokit",
"id": 3430433,
"avatar_url": "https://avatars0.githubusercontent.com/u/3430433?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/octokit",
"html_url": "https://github.com/octokit",
"followers_url": "https://api.github.com/users/octokit/followers",
"following_url": "https://api.github.com/users/octokit/following{/other_user}",
"gists_url": "https://api.github.com/users/octokit/gists{/gist_id}",
"starred_url": "https://api.github.com/users/octokit/starred{/owner}{/repo}",
"subscriptions_url": "cats"
}
}]
print mylist[0]['id']
这将返回打印
mylist
的第0个(即第一个)成员的id
属性,该属性等于417862
,假设您正在使用熊猫:
生成一个函数并返回列表的第一个值
def get_json_data(mylist):
return mylist[0]
创建新列mn并应用该函数
df['new_col']=df.apply(lambda df: get_json_data(df['old_col']),axis=1)
一旦你拿到了gata,就把它正常化
pd.io.json.json_normalize(df['new_col'])
希望这有帮助:)你在使用什么编程语言/库?我在使用python!!可能重复的