简体   繁体   English

如何在Python中返回simplejson

[英]How to return simplejson in Python

I am a noob and I am working on a Python project that uses json. 我是菜鸟,我正在研究使用json的Python项目。 My goal is to call an object ("object.json()") and get the data. 我的目标是调用一个object ("object.json()")并获取数据。

The only thing is I can only import simplejson and not import json . 唯一的是我只能导入 simplejson,不能导入json

How do I call on an object with simplejson eg("object.simplejson()) <----- Obviously not right but this is just an example. 我该如何用simplejson调用对象 eg("object.simplejson()) <-----显然不正确,但这只是一个例子。

Btw I am using MAC Sierra 10.12.6 顺便说一句我正在使用MAC Sierra 10.12.6

You just need to use the dumps method: 您只需要使用dumps方法:

import simplejson
encoded = simplejson.dumps(myobject)

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

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