---
title: "python写json示例"
author: "polyahu"
date: "2013-02-08T22:06:28Z"
tags: []
categories: ["编程语言"]
slug: "python-json"
draft: false
lastmod: "2013-02-08T22:06:28Z"
id: 1797535
url: "https://polyahu.iteye.com/blog/1797535"
---

```python

#!/usr/bin/python

import json

source = '{"name":"polyahu", "type":"title"}'
f = open('./json.data')
j = json.loads(source)
r = json.load(f)
s = json.dumps(j)

print "j's type",
print type(j)
print "s's type",
print type(s)


```


json.loads()和json.dumps()是将str类型和dict类型互相转换。