简体   繁体   English

使用Python从JSON文件提取数据

[英]Using Python to extract data from JSON file

I was ask to extract data from a JSON file using Python. 我被要求使用Python从JSON文件中提取数据。 The original JSON file looks like this: 原始JSON文件如下所示:

{"votes": {"funny": 15, "useful": 48, "cool": 18}, "user_id": "JkeCKyEaQlbLd9uZYl4DjA", "name": "LiiLii C.", "url": "http://www.yelp.com/user_details?userid=JkeCKyEaQlbLd9uZYl4DjA", "average_stars": 3.2258064516128999, "review_count": 31, "type": "user"}

{"votes": {"funny": 0, "useful": 2, "cool": 0}, "user_id": "cs91PAsv6esdWAaSkzm2lg", "name": "Jan Ellen T.", "url": "http://www.yelp.com/user_details?userid=cs91PAsv6esdWAaSkzm2lg", "average_stars": 3.0, "review_count": 4, "type": "user"}

And I was asked to use Python to extract this file and give an output file that looks like this: 然后有人要求我使用Python提取此文件,并提供一个类似于以下内容的输出文件:

name    city    state   stars   review_count    main_category

Southern California Medical Group   Los Angeles CA  3.5 2   Medical Centers

Harvard Square Shiatsu  Cambridge   MA  4.0 4   Massage

Faith & Glory Collective    Kitchener   ON  4.0 2   Tattoo

Von's Records & Posters West Lafayette  IN  3.5 3   Music & DVDs

JP's Java   Austin  TX  3.5 85  Food

I am really confused by this assignment because I don't understand why the output file has nothing similar to the original JSON file. 我对此工作感到很困惑,因为我不明白为什么输出文件与原始JSON文件没有相似之处。 And is this because I need to extract data from the JSON file through each provided link? 这是因为我需要通过每个提供的链接从JSON文件提取数据吗? And if this is the case, how should I do this task? 如果是这种情况,我应该怎么做呢?

If you're accurately quoting what has been asked, you need to gather more details about the users mentioned in your JSON, in order to compile the required output. 如果您准确地引用了要求的内容,则需要收集有关JSON中提到的用户的更多详细信息,以便编译所需的输出。 Yelp has an API which might help you gather the required data, given a user ID. Yelp有一个API,可以在给定用户ID的情况下帮助您收集所需的数据。 Anyhow, doesn't look like this is really a JSON question. 无论如何,看起来这不是一个真正的JSON问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM