티스토리 뷰

SWDesk/Web

Python JSON Example

bizmaker 2020. 9. 30. 01:45

<Python source>

import urllib.parse
import urllib.request
import json

URL1 = "https://www.bilientsvc.net/ZezoUP/PHPJSON01.php"
Data0 = {'aa1':'aa11'}
Data1 = urllib.parse.urlencode(Data0)
Data1 = Data1.encode('utf8')
req = urllib.request.Request(URL1, Data1)
res = urlopen(req)
res1 = res.read().decode('utf8')
print(res1)
dict1 = json.loads(res1)
print(dict1)
rst1 = dict1['result']
print(rst1)
for Data1 in rst1:
    print(Data1['Commandname'], '>', Data1['CommandNo'])

<Result>

{"result":[{"Commandname":"Commandname1","CommandNo":"CommandNo1"}]}

{'result': [{'Commandname': 'Commandname1', 'CommandNo': 'CommandNo1'}]}
[{'Commandname': 'Commandname1', 'CommandNo': 'CommandNo1'}]
Commandname1 > CommandNo1

 

반응형

'SWDesk > Web' 카테고리의 다른 글

(X)Python Code for Collecting Weather Data  (0) 2020.10.01
기상정보 수집을 위한 웹 소스(1)  (0) 2020.10.01
PHP JSON Example  (0) 2020.09.28
Python XML Example  (0) 2020.09.27
HTML, Dialog  (0) 2020.09.14