I have a string, which contains valid json. I'd like to add that json as a JField in a larger json4s AST I'm building, but it'd be nice to avoid having to parse the json into an AST first. I trust it.
我有一个字符串,其中包含有效的json。我想在我正在构建的更大的json4s AST中添加json作为JField,但是最好避免必须首先将json解析为AST。我相信它。
// this would work, but I'd prefer to avoid parsing something I
// happen to already know contains valid json
val rawJsonStr = "..."
val spliced = JField("foo", parse(rawJsonStr))
Is there a way beyond building the AST, converting it to json, then doing text manipulation?
有没有办法超越构建AST,将其转换为json,然后进行文本操作?
1 个解决方案
#1
0
I tried to do the same. After several attempts I realized that this was not a good idea.
我也尝试过这样做。经过几次尝试,我意识到这不是一个好主意。
Since the second element of JField("foo", _) is supposed to be a JValue. When I put a string in it ended up being an escaped string.
因为JField的第二个元素(“foo”,_)应该是JValue。当我把一个字符串放入其中时最终成为一个转义字符串。
Maybe you can get around this.
也许你可以解决这个问题。
#1
0
I tried to do the same. After several attempts I realized that this was not a good idea.
我也尝试过这样做。经过几次尝试,我意识到这不是一个好主意。
Since the second element of JField("foo", _) is supposed to be a JValue. When I put a string in it ended up being an escaped string.
因为JField的第二个元素(“foo”,_)应该是JValue。当我把一个字符串放入其中时最终成为一个转义字符串。
Maybe you can get around this.
也许你可以解决这个问题。