gpt4 book ai didi

parsing - SnakeYAML:解析时如何禁用下划线剥离?

转载 作者:行者123 更新时间:2023-12-02 14:29:38 34 4
gpt4 key购买 nike

这是我的问题。我有包含以下对的 YAML 文档:

run_ID: 2010_03_31_101

当这个 get 被解析时 org.yaml.snakeyaml.constructor.SafeConstructor.ConstructYamlInt:159下划线被删除,构造函数返回 Long 20100331101而不是未经修改的String "2010_03_31_101"我真正需要的。

问题:如何我可以禁用此行为并强制解析器使用 String 构造函数吗而不是长?

最佳答案

好的。从他们的邮件列表中得到答案。在这里

Hi, according to the spec (http://yaml.org/type/int.html): Any “_” characters in the number are ignored, allowing a readable representation of large values

You have a few ways to solve it. 1) do not rely on implicit types, use quotes (single or double) run_ID: '2010_03_31_101'

2) Turn off resolver for integers (as it is done here for floats) link 1 link 2

3) Define your own pattern for int link 3

Please be aware that when you start to deviate from the spec other recipients may fail to parse your YAML document. Using quotes is safe.

  • Andrey

关于parsing - SnakeYAML:解析时如何禁用下划线剥离?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2723321/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com