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

编程入门 行业动态 更新时间:2024-10-25 20:19:24
本文介绍了我可以在同一个json文件中的另一个对象中引用一个json对象吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试使用json开发测试自动化框架来描述数据. 我有一个看起来像这样的json文件:

I'm trying to develop a test automation framework using json to describe data. I have a json file which looks like this:

{ "preparation":{ "configuration":[ { "config1":{ "src_configfile":"/home/xxx/etc/src_config1.cfg", "dest_configfile":"/home/xxx/etc/abc.cfg" } }, { "config2":{ "src_configfile":"/home/xxx/etc/src_config2.cfg", "dest_configfile":"/home/xxx/etc/xyz.cfg" } } ], "executable_info1":[ { "login_info":{ "hostname":"abc.dw", "username":"xyz", "password":"*******" } }, { "command":{ "folderpath":"/home/xxx/yyy/bin", "processname":"sys.exe", "parameters":"-d" } } ], }, "execution":[ { "test_case1":{ "folderpath":"/home/xxx/testscripts", "scriptname":"test_case1.py", ***???????????Can I access the config1 object here???????????? "config_file"="preparation.configuration[0].config1.dest_configfile"*** } }, { "test_case1":{ "folderpath":"/home/xxx/testscripts", "scriptname":"test_case2.py", ***"config_file"="preparation.configuration[1].config2.dest_configfile"*** } } ] }

我需要针对不同的测试用例使用不同的配置文件.我可以在执行中引用准备对象的config1对象吗???

I need to use different config files for different test cases. Can I reference the config1 object of preparation object in the execution???

推荐答案

不,您不能这样做,至少不能直接这样做.首先,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.

更多推荐

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

本文发布于:2023-11-22 08:28:17,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1616691.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:象中   对象   文件   在同一个   json

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!