如何在 Google App Engine 中解析 JSON? [英] How can I parse JSON in Google App Engine?

查看:41
本文介绍了如何在 Google App Engine 中解析 JSON?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将 JSON 字符串解析为 Google App Engine (python) 下的对象.你有什么建议吗?编码/字符串化的东西也会很好.您推荐的内容是内置的还是必须包含在我的应用程序中的库?它安全吗?谢谢.

I'd like to parse a JSON string into an object under Google App Engine (python). What do you recommend? Something to encode/stringify would be nice too. Is what you recommend built in, or a library that I have to include in my app? Is it secure? Thanks.

推荐答案

考虑使用 Django 的json 库,包含在 GAE 中.

Consider using Django's json lib, which is included with GAE.

from django.utils import simplejson as json

# load the object from a string
obj = json.loads( string )

上面的链接有 Django 序列化程序的例子,这里是 simplejson 的文档.

The link above has examples of Django's serializer, and here's the link for simplejson's documentation.

如果您正在考虑存储 Python 类实例或对象(而不是列表、字符串、数字和字典的组合),您可能需要查看 pickle.

If you're looking at storing Python class instances or objects (as opposed to compositions of lists, strings, numbers, and dictionaries), you probably want to look at pickle.

希望能帮到你.

顺便说一句,要在 GAE 上运行 Django 1.0(而不是 Django 0.96),您可以在 main.py 中使用以下调用,根据 这篇文章:

Incidentally, to get Django 1.0 (instead of Django 0.96) running on GAE, you can use the following call in your main.py, per this article:

from google.appengine.dist import use_library
use_library('django', '1.0')

<小时>

带有 Python 2.7 的 Google App Engine 1.6.0 中的原生 JSON 支持

从 Google App Engine 1.6.0 开始,您可以使用 Python2.7 运行时 通过在app.yaml中添加runtime:python27,然后就可以通过import json导入原生JSON库.


Native JSON support in Google App Engine 1.6.0 with Python 2.7

As of Google App Engine 1.6.0, you can use the Python 2.7 runtime by adding runtime: python27 in app.yaml, and then you can import the native JSON library with import json.

这篇关于如何在 Google App Engine 中解析 JSON?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆