且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

我可以在同一个json文件中的另一个对象中引用一个json对象吗?

更新时间:2023-01-08 11:40:29

不,您不能这样做,至少不能直接这样做.首先,JSON不支持循环引用.

No, you can't do that, at least not directly. For a start, JSON doesn't support circular references.

您可能会考虑使用诸如jsonpath之类的库,该库允许您按模式引用元素,但是无论值是实际值还是对其他分支的引用,您都倾向于先验.

You might consider using a library such as jsonpath that allows you to reference elements by pattern, but you would tend to need apriori whether a value was an actual value or a reference to some other branch.