: This article mainly introduces how PHP processes json data from Python Post. if you are interested in PHP tutorials, refer to it. Recently, Python has been used to process some json data, but some problems have been encountered during the process, so it is recorded.
1. Python Post json format data to the server:
I checked some materials, mostly like this:
__author__ = 'jiezhi'import urllibimport urllib2data = {'name': 'jiezhi', 'age': '24'}ret = urllib2.urlopen(url='http://jiezhiblog.com/test.php', data=urllib.urlencode(data))print ret.read()
However, php usually has the array type.
The following code is used after several times:
__author__ = 'jiezhi'import urllib2import jsondata = {'name': 'jiezhi', 'age': '24'}ret = urllib2.urlopen(url='http://jiezhiblog.com/test.php', data=json.dumps(data))print ret.read()
2. PHP problems
With the changed Python code, we found that no data was obtained from $ _ POST, so we used file_get_contents ("php: // input") to obtain the submitted data:
In this case, the submitted data can be obtained correctly.
Starting address: http://jiezhiblog.com/archives/366
The above describes how PHP processes json data from Python's Post, including some content, and hopes to help friends who are interested in PHP tutorials.