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

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

问题描述

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

解决方案

考虑使用 Django的json lib ,它包含在GAE中。

 来自django。 utils import simplejson as json 

#从字符串中加载对象
obj = json.loads(string)

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



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

我希望有帮助。

顺便提一句,要获得Django 1.0(而不是Django 0.96)运行o n GAE,您可以在main.py中使用以下调用:本文

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






编辑:原生JSON支持Google App Engine 1.6.0与Python 2.7



从Google App Engine 1.6.0开始,您可以通过在<$ c $中添加 runtime:python27 来使用Python 2.7运行时 c> app.yaml ,然后您可以使用 import json 导入本机JSON库。


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.

解决方案

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 )

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

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.

I hope that helps.

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')


Edit: 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天全站免登陆