我想問這是我的JSON檔案。如果我想把我的'c'改為'9',我如何為資料寫?
{
'x'。4,
'y': 5,
'z': [
{
'a': 1,
'b': 2,
'c': 3
import urllib.request
import json
data = ?????
myurl = "http://192.168.1.10:8888/testJSON"。
req = urllib.require.Request(myurl)
req.add_header('Content-Type'/span>, 'application/json; charset=utf-8'/span>)
jsondata = json.dumps(data)
jsondataasbytes = jsondata.encode('utf-8') # 需要是位元組數。
req.add_header('Content-Length', len(jsondataasbytes))
response = urllib.request.urlopen(req, jsondataasbytes)
@BhagyeshDudhediya提供的解決方案是可行的:
import urllib.request
import json
data['z'][0]['c'] = 9.
myurl = "http://192.168.1.10:8888/testJSON"/span>
req = urllib.require.Request(myurl)
req.add_header('Content-Type'/span>, 'application/json; charset=utf-8'/span>)
jsondata = json.dumps(data)
jsondataasbytes = jsondata.encode('utf-8') # 需要是位元組數。
req.add_header('Content-Length', len(jsondataasbytes))
response = urllib.request.urlopen(req, jsondataasbytes)
uj5u.com熱心網友回復:
只要這樣做。data['z'][0]['c'] = 9
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/332310.html
標籤:
