【问题标题】:Google appengine, ndb, and Json谷歌应用引擎、ndb 和 Json
【发布时间】:2012-04-18 15:08:00
【问题描述】:

我有一个属性存储为 JSON 对象,如下所示:

content  = ndb.JsonProperty()

当我这样做时,我得到了这个错误:

   line 1614, in _to_base_type
    return json.dumps(value, 2)
AttributeError: 'module' object has no attribute 'dumps'

在 ndb 模型类中。

作为ndb.TextProperty,它可以正常工作。也许我发送的 JSON 错误,这是我发送的 JSON 对象:

{posttext: "What is your earliest memory of WWII?", linkdata: ""}

【问题讨论】:

    标签: json google-app-engine app-engine-ndb


    【解决方案1】:

    您的应用中是否有名为“json.py”的模块或名为“json”的包?这将覆盖 ndb 尝试导入的 json 模块。解决方案是为该模块或包选择不同的名称。

    【讨论】:

      【解决方案2】:

      当我尝试时,您所描述的效果很好:

      from google.appengine.ext import ndb
      class TestModel(ndb.Model):
        foo = ndb.JsonProperty()
      t = TestModel(foo={"posttext": "What is your earliest memory of WWII?", "linkdata": ""})
      t.put()
      Key('TestModel', 7001)
      

      您能否更详细地说明您是如何做到这一点的?和上面的sn-p有什么区别?

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2013-02-26
        • 2012-10-02
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多