我收到以下錯誤,同時嘗試與json4s解析JSON:如何在使用json4s時設置Jackson解析器功能?
Non-standard token 'NaN': enable JsonParser.Feature.ALLOW_NON_NUMERIC_NUMBERS to allow
如何啓用此功能?
我收到以下錯誤,同時嘗試與json4s解析JSON:如何在使用json4s時設置Jackson解析器功能?
Non-standard token 'NaN': enable JsonParser.Feature.ALLOW_NON_NUMERIC_NUMBERS to allow
如何啓用此功能?
假設你ObjectMapper對象被命名爲mapper
:
val mapper = new ObjectMapper()
// Configure NaN here
mapper.configure(JsonParser.Feature.ALLOW_NON_NUMERIC_NUMBERS, true)
...
val json = ... //Get your json
val imported = mapper.readValue(json, classOf[Thing]) // Thing being whatever class you're importing to.
嗯...我認爲我的錯誤發生在我閱讀JSON文檔時: val json = parse(jsonString) – arosca
@arosca恐怕沒有更多的上下文/代碼我不能完全看到關係。 –
@Nathaniel福特,設置我在正確的道路上感謝!
我最終看到了parse()方法的源代碼(這是我應該首先完成的)。此作品:
import com.fasterxml.jackson.core.JsonParser
import com.fasterxml.jackson.databind.ObjectMapper
import org.json4s._
import org.json4s.jackson.Json4sScalaModule
val jsonString = """{"price": NaN}"""
val mapper = new ObjectMapper()
// Configure NaN here
mapper.configure(JsonParser.Feature.ALLOW_NON_NUMERIC_NUMBERS, true)
mapper.registerModule(new Json4sScalaModule)
val json = mapper.readValue(jsonString, classOf[JValue])
如果他們幫助你,請不要忘記upvote/accept answers!你將來更有可能獲得幫助。 –