【问题标题】:Insert JSON data into database for python将JSON数据插入数据库以供python
【发布时间】:2018-06-23 11:49:00
【问题描述】:

我目前正在做一个从foursquare 中删除数据的系统。现在我已经使用 python 和美丽的汤从网站上删除了评论,并有一个如下所示的 json 文件

{"review": "From sunset too variety food u cant liked it.."}{"review": "Byk motor laju2"}{"review": "Good place to chill"}{"review": "If you wan to play bubble and take photo, here is the best place"}{"review": "Scenic view for weekend getaway... coconut shake not taste as original klebang coconut shake..."}{"review": "Getting dirtier"}{"review": "Weekend getaway!"}{"review": "Good for casual walk & watching sunset with loved ones since my last visit macam2 ade kat sini very packed during public holidays"}{"review": "Afternoon time quite dry..beach is normal. Maybe evening/night might be better. The coconut shake they add vanilla ice cream,hmmm"}{"review": "Pantai awesome beb"}{"review": "Nice place for picnic"}{"review": "Cannot mandi here. Good place for recreation.. Calm place for weekdays! Haha"}{"review": "Very bz place. Need to go there early if you want to lepak. If not, no parking for you"}{"review": "So many good attraction here, worth a visit"}{"review": "Beautiful place for sunset"}{"review": "New beach!  Like all beaches, awesome view & windy.  Some stretch got many small crabs."}{"review": "There is bustel \"hotel in a bus\" can get coconut shake or fried seafood in the evening at 5pm. Bustel rate is from RM80. Bus cafe, bus toilet... Total bus transformation"}{"review": "Too crowded la"}{"review": "Muzium kapal selam closed since 1/3 until further notice..\ud83d\ude29"}{"review": "If you are looking for public toilets, look for a red bus. An old bus was modified and transformed to operate as toilets. Cool."}{"review": "Most of the shops closed after 12 midnight..helloo,this place should be the place for the late nighters..late night supposed to be the peak hour for business..live band bar maybe?? :-P"}

我的问题是如何立即将数据插入数据库?可以使用 MYSQL,还是应该使用 PyMongo。

【问题讨论】:

  • 您可以为此使用 any 数据库。您选择哪一个取决于您已经熟悉的系统、项目已经使用的系统(如果有的话)、项目可能还有哪些其他要求等.​​..
  • Pymongo 是一个 Python 包,这意味着您将使用 MongoDB 作为数据库。

标签: python mysql json django pymongo


【解决方案1】:

这取决于您的使用情况。基本上,MongoDB 适合 JSON 文档,因此,您将能够“直接”插入 Python 对象。如果您想/需要使用 MySQL,您可能需要在插入之前执行一些转换。查看此帖子了解更多信息:Inserting JSON into MySQL using Python

【讨论】:

    【解决方案2】:

    您可以将您的 json 转换为字符串 (json.dumps()) 并存储在字符字段中。

    或者,Django 在使用 Postgres (docs) 时支持 JSONField,这有一些额外的功能,比如在 json 中查询

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-03-25
      • 2019-04-01
      • 1970-01-01
      • 2019-10-25
      • 1970-01-01
      • 2021-10-25
      • 2018-05-19
      • 1970-01-01
      相关资源
      最近更新 更多