json-string을 python 개체로 변환해야합니다. 객체 란 다음과 같은 "새로운"python3 객체를 의미합니다.json을 개체로 변환하는 방법?
class MyClass(object):
예를 들어 jsonpickle 설명서에서 여러 가지 도움말을 발견했습니다. 하지만 내가 찾은 것은 객체를 json으로 먼저 변환 한 후 튜토리얼로 변환 한 후 거꾸로 변환하는 것입니다.
json-string을 Rest-API으로 변환하고 싶습니다.
그것은 jsonpickle 내 수업이 변환 할 수 없습니다 것을 나에게 매우 분명TypeError: the JSON object must be str, bytes or bytearray, not 'method'
(목표, 경기 :
이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)
이 결과 : 여기
내가 지금까지 한 일이다) 왜냐하면 나는 어떤 클래스에서 출력을 변환해야하는지 jsonpickle에게 말하지 않기 때문이다. 문제는 jsonpickle에게 객체의 JSON을 Match 유형으로 변환하는 방법을 알려주지 못한다는 것입니다. 목표 목록이List<Goal>
유형이어야한다고 어떻게 알 수 있습니까? 위의
obj = jsonpickle.decode(result.content) # NOTE: `.content`, not `.json`
obj = result.json()
그러나 아무도 당신에게 당신이 원하는 것을() (dicitonary하지 파이썬 객체)를 제공하지 않습니다 :
'OBJ = jsonpickle.decode (result.content)는'=> 이렇게하면 사전을 제공 할 것입니다. – falsetru
'obj = result.json()'도 사전을 줄 것입니다. – falsetru