Python操作json数据的一个简单例子

作者:junjie 时间:2022-10-23 17:09:37 

更多的信息,可以参考python内部的json文档:
python>>> help(json)
或者官方文档: http://docs.python.org/library/json.html#module-json.

下面给出一个使用python解析json的简单例子:


#!/usr/bin/python
import json
#Function:Analyze json script
#Json is a script can descript data structure as xml,
#for detail, please refer to "http://json.org/json-zh.html".

#Note:
#1.Also, if you write json script from python,
#you should use dump instead of load. pleaser refer to "help(json)".

#json file:
#The file content of temp.json is:
#{
# "name":"00_sample_case1",
# "description":"an example."
#}
#f = file("temp.json");
#s = json.load(f)
#print s
#f.close

#json string:
s = json.loads('{"name":"test", "type":{"name":"seq", "parameter":["1", "2"]}}')
print s
print s.keys()
print s["name"]
print s["type"]["name"]
print s["type"]["parameter"][1]


PS:关于json操作,这里再为大家推荐几款比较实用的json在线工具供大家参考使用:

在线JSON代码检验、检验、美化、格式化工具:
http://tools.jb51.net/code/json

JSON在线格式化工具:
http://tools.jb51.net/code/jsonformat

在线XML/JSON互相转换工具:
http://tools.jb51.net/code/xmljson

json代码在线格式化/美化/压缩/编辑/转换工具:
http://tools.jb51.net/code/jsoncodeformat

在线json压缩/转义工具:

http://tools.jb51.net/code/json_yasuo_trans

C语言风格/HTML/CSS/json代码格式化美化工具:
http://tools.jb51.net/code/ccode_html_css_json

标签:Python,json
0
投稿

猜你喜欢

  • Mysql如何查看是否使用到索引

    2024-01-25 09:58:06
  • Django使用Celery加redis执行异步任务的实例内容

    2022-08-25 18:09:53
  • Go语言基础设计模式之策略模式示例详解

    2024-05-25 15:11:01
  • pytorch 实现删除tensor中的指定行列

    2023-05-22 14:26:26
  • 详解超星脚本出现乱码问题的解决方法(Python)

    2022-11-21 02:40:42
  • 详解Django中的ifequal和ifnotequal标签使用

    2023-06-24 05:07:04
  • python中的annotate函数使用

    2021-04-10 01:52:59
  • 基于OpenCv实现的人脸识别(附Python完整代码)

    2022-08-10 21:49:27
  • python的列表生成式,生成器和generator对象你了解吗

    2022-05-15 15:10:04
  • MySQL用truncate命令快速清空一个数据库中的所有表

    2024-01-18 16:05:29
  • 一个月入门Python爬虫学习,轻松爬取大规模数据

    2022-03-10 11:04:26
  • 使用Python操作FTP实现上传和下载的方法

    2023-03-09 20:49:51
  • Golang加权轮询负载均衡的实现

    2024-02-01 04:41:57
  • golang 结构体初始化时赋值格式介绍

    2024-04-26 17:26:11
  • .NET之生成数据库全流程实现

    2024-01-16 05:08:48
  • golang定时任务cron项目实操指南

    2023-08-26 00:21:40
  • Go语言区别于其他语言的特性

    2023-06-26 02:52:10
  • Python 基于TCP 传输协议的网络通信实现方法

    2023-06-18 22:04:01
  • css2.1实现多重背景和边框效果

    2010-06-23 19:02:00
  • 透彻掌握ASP分页技术

    2009-03-09 18:26:00
  • asp之家 网络编程 m.aspxhome.com