java如何解析postmancollection?
目标:
我试图解析postman_echo集合json,并将结果持久化到磁盘上的一个新json副本中,生成与原始文件相同的文件
我更喜欢该语言中的内置数据结构,但使用json库也应该不错。不确定Antlr4是否是更好的方法
后续问题
在post请求主体中是否允许任何有效的嵌套json
更新: https://github.com/chakpongchung/postman-parser 最后我们提出了这个令人满意的解决方案
你可以在下面搜索框中键入要查询的问题!
目标:
我试图解析postman_echo集合json,并将结果持久化到磁盘上的一个新json副本中,生成与原始文件相同的文件
我更喜欢该语言中的内置数据结构,但使用json库也应该不错。不确定Antlr4是否是更好的方法
后续问题
在post请求主体中是否允许任何有效的嵌套json
更新: https://github.com/chakpongchung/postman-parser 最后我们提出了这个令人满意的解决方案
# 1 楼答案
zoran提到的另一种方法是,如果结构不是太动态(使用Play JSON),则创建一个case类。这将使比较结果更容易
然后,您只需执行以下操作:
# 2 楼答案
解析器中存在多个问题,其中大多数问题是您试图使用默认解析器将Json对象作为字符串处理。例如,在请求中,您将头作为Seq[String]处理,而实际上它是(键、值)对的Seq。对于这种特殊情况,您应该将其更改为以下内容:
如果需要,可以将标题转换为Seq[String],但必须为此编写自定义读取。 在上述情况下,还存在缺少描述的情况,因此您希望使用默认值处理该情况。 在其他一些地方,你也有这样的问题需要处理,例如“回应”
我注意到的另一个问题是如何处理Json字符串中的“type”属性。Type是保留关键字,您可以通过将其包装在``中来处理它,例如
# 3 楼答案
我不确定我是否理解您的问题,但如果您试图迭代json字符串,您可能会尝试以下方法: