如何从JSON文件中读取值并将其存储在Python中的temp变量中? [英] How to read a value from a JSON file and store it in temp variable in Python?

查看:324
本文介绍了如何从JSON文件中读取值并将其存储在Python中的temp变量中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从JSON文件读取单个值并将其存储在python中的temp变量中?



我尝试过:



我是新手,如果示例代码是共享的话会很有帮助

How to read single value from a JSON file and store it in temp variable in python?

What I have tried:

I am new to this and would be helpful if sample code is shared

推荐答案

你需要看看对于Python语言的JSON库,可以将JSON字符串序列化和反序列化为运行时对象。



如果您使用的是Python 2,请考虑以下内容:

18.2。 json - JSON编码器和解码器 - Python 2.7.13文档 [ ^ ]。该页面上提供了可用于您自己项目的软件包的示例演示。你有兴趣在那里指定编码器和解码器。



从字符串解码到对象后,你可以获取该属性的值。浏览该链接以了解更多信息。
You need to look for a JSON library in Python language, that would let you serialize and deserialize the JSON strings, to runtime objects.

If you're using Python 2, consider the following,
18.2. json — JSON encoder and decoder — Python 2.7.13 documentation[^]. There is a sample demonstration of the package available on that page that you can use for your own project. There are encoders and decoders specified there, that you are interested in.

Once decoded from string, to an object, you can fetch the value of that property. Go through that link to learn more.


这篇关于如何从JSON文件中读取值并将其存储在Python中的temp变量中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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