问题描述
我从服务中收到一个非常深的JSON对象字符串,我必须将其解析为JSON对象,然后将其映射到类。
I'm receiving a quite deep JSON object string from a service which I must parse to a JSON object and then map it to classes.
如何转换在Kotlin中对象的JSON字符串?
How can I transform a JSON string to object in Kotlin?
之后映射到各个类,我使用的是Jackson的StdDeserializer。问题出现在对象具有也必须被反序列化为类的属性的时刻。我无法在另一个反序列化器中获取对象映射器,至少我不知道如何。
After that the mapping to the respective classes, I was using StdDeserializer from Jackson. The problem arises at the moment the object had properties that also had to be deserialized into classes. I was not able to get the object mapper, at least I didn't know how, inside another deserializer.
提前感谢您的帮助。优选地,本地,我正在尝试减少我需要的依赖项的数量,所以如果答案仅用于JSON操作并且解析它就足够了。
Thanks in advance for any help. Preferably, natively, I'm trying to reduce the number of dependencies I need so if the answer is only for JSON manipulation and parsing it'd be enough.
推荐答案
您可以使用此库 https://github.com/cbeust/klaxon
Klaxon是一个轻量级的库,用于在Kotlin中解析JSON。
Klaxon is a lightweight library to parse JSON in Kotlin.
这篇关于如何在Kotlin中解析JSON?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!