在python中,JSONDecoder在默认情况下预先形成null到None的转换,如下所示。我如何将空-> to的翻译更改为不同的内容。即空->‘猫’
class json.JSONDecoder([encoding[, object_hook[, parse_float[, parse_int[, parse_constant[, strict[, object_pairs_hook]]]]]]])
Simple JSON decoder.
Performs the following translations in decoding by default:
JSON
我希望将从web服务获得的JSON解析为对象结构。因此,我使用一个json.JSONDecoder方法实现了一个object_hook子类。我还没有找到一种为给定数据选择正确类的好方法。对于具有相同属性的类,似乎不可能确定正确的属性,因为这需要知道键。让我们来看看一个例子:
我有以下课程:
class Post:
def __init__(self, title, user=None, group=None):
self.title = title
self.user = user
self.group = group
class Gr