I am trying to have a python client send a post request which contains nested JSON like such
{"nested":{"field1":"response1", "field2":"response2"}}
My python code is here
from urllib.parse import urlencode
from urllib.request import Request, urlopen
url="http://localhost/api/vscore.php"
post_fields={"nested":{"field1":"response1", "field2":"response2"}}
request = Request(url, urlencode(post_fields).encode())
json = urlopen(request).read().decode()
print(json)
PHP code:
print_r($_POST["nested"]);
returns
{'field2': 'response2', 'field1': 'response1'}
but when I try to access "field1" with $_POST["nested"]["field1"], it returns this:
{
instead of returning "response1". How can I get my code to return fields in nested JSON?