如何使用Python3.4从PHP服务器解析此API JSON流?
import requests
import json
url = 'http://api.example.com'
parameters = {'code':1, 'user': 'default', 'password': 'default'}
headers = {'content-type': 'application/json'}
response = requests.post(url, data = json.dumps(parameters), headers=headers)
text = response.text
data = json.loads(text)
print (json.dumps(data, sort_keys=True, indent=4))
输出
{
"streaming": {
"1": {
"product": "01",
"progress": "SUCCESS",
"proces": "IMPORT",
"datetime": "2015-11-23 00-00-00",
"user": "David"
},
"10": {
"product": "02",
"progress": "succes",
"proces": "Sending email",
"datetime": "2015-11-23 00-00-01",
"user": "David"
}}}
我试图过滤字典,但我不能,因为使用非字符串作为键并且我得到了错误。
答案 0 :(得分:1)
使用json_decode()
来解析你的json对象。
$json = "your content"
$decoded = json_decode($json);
print_r($decoded);