Bir json dizesini python nesnesine dönüştürmem gerekiyor. Nesnenin derken demek gibi "yeni" python3 nesnesi: Ben jsonpickle belgelere örneğin birkaç yardım buldumJson nesnesine nasıl dönüştürülür?
class MyClass(object):
. Ama bulduğum her şey nesneyi json'a dönüştüren ve sonradan geriye dönüş yapan öğreticilerdir.
Bir json dizesini Rest-API'dan dönüştürmek istiyorum.
Bu jsonpickle Derslerimi nasıl çeviririm olamaz bana göre gayet açıktırTypeError: the JSON object must be str, bytes or bytearray, not 'method'
(Hedef, Match:
import requests
import jsonpickle
class Goal(object):
def __init__(self):
self.GoaldID = -1
self.IsPenalty = False
class Match(object):
def __init__(self):
self.Goals = []
headers = {
"Content-Type": "application/json; charset=utf-8"
}
url = "https://www.openligadb.de/api/getmatchdata/39738"
result = requests.get(url=url, headers=headers)
obj = jsonpickle.decode(result.json)
print (obj)
Bu sonuçlanır: Burada
şimdiye kadar yapmış budur), çünkü jsonpickle'a hangi sınıfta çıktı dönüştürüleceğini söylemiyorum. Sorun Jsonpickle'a JSON'u nesne türündeki nesneye dönüştürmeyi nasıl söyleyeceğimi bilmiyorum. Ve hedefler listesininList<Goal>
türünde olması gerektiğini nasıl anlarım? Yukarıdakilerin
obj = jsonpickle.decode(result.content) # NOTE: `.content`, not `.json`
obj = result.json()
Ama hiçbiri size ne istediğinizi() (dicitonary değil piton nesne) verecektir:
'obj = jsonpickle.decode (result.content)' => Bu size bir sözlük verecektir. – falsetru
'obj = result.json()' ayrıca bir sözlük de verecektir. – falsetru